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
sharepoint foundation 2010 on 32 bit?
xml to array
Backup Exec 12 - can't install any updates - gives error 1324 "The path Program Files contains an invalid character"
How to program well
How to generate an HTML file if I've got the HTML body?
can't get iPhone to connect to Exchange 2010 from outside...
Calculating the date.
Files scp'ed from Unix servers to Win XP (running WinSSHD V5 ) could not be deleted on the PC
Windows 2003 R2 and WSS 3
URGENT: Solaris virtual printer lpd printing setup