Microsoft
Software
Hardware
Network
Question : Using SQL MAX Function
My goal is to retrieve only the most recent eventdate record for each company (id_company). In this first example, I'm seeing multiple records for both companies 12937 and 12933.
select id_event, id_company, updatedescription, eventdate
from events e
where e.id_company in (12937, 12933 )
and
(
(e.UpdateDescription = 'Rating Affirmed')
OR (e.UpdateDescription = 'Rating Assigned')
OR (e.UpdateDescription = 'Rating Change - Downgrade')
OR (e.UpdateDescription = 'Rating Change - Upgrade')
)
order by id_company;
In this example, I'm trying to pull only the most recent eventdate record for each company by using SELECT MAX(e2.EventDate). It mysteriously works for only one company (12937) by pulling only the max eventdate row but I get no records at all for 12933. Unfortunately, I'm using SQL 2000 so I can't use some of the newer SQL functions.
select id_event, id_company, updatedescription, eventdate
from events e
where ( e.eventdate =
(
select MAX(e2.EventDate)
from events e2
where e2.id_company = e.id_company
and
(
(e.UpdateDescription = 'Rating Affirmed')
OR (e.UpdateDescription = 'Rating Assigned')
OR (e.UpdateDescription = 'Rating Change - Downgrade')
OR (e.UpdateDescription = 'Rating Change - Upgrade')
)
)
)
and e.id_company in (12937, 12933 )
order by id_company, eventdate desc;
Answer : Using SQL MAX Function
"VESA 75 and 100 LCDs use 4mm screws with 0.7 pitch." as specified in the document ....
Random Solutions
Timers in Foxpro
Passing a structure from VBA in Excel to a C DLL
how to prevent others to see my website without logging in
Pervasive SQL 9.5 - odbc SELECT Query - DATE = '0000-00-00'
Ping from Cisco Switch
How to deny write to the desktop for users?
SBS 2008 SharePoint Companyweb Layout Missing
I have a Toshiba Satellite A105 Laptop, and Hard Drive From Dell Vostro 1500 w/ Win 7 wont boot?
Deploy Printer Drivers to WinXP Computers
use desktop monitor screen with laptop