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
High Insert/Update time because of Trigger
Vmware Virtual Centre Service not starting
2 raid controllers managing the disk array
how to avoid echo in 1 on 1 video chat / conference-system with FMS 3,5
How do i create a SCOM 2007 SP1 cluster?
Convert Vmware guest, increase processors ok?
Netlogon Service stopped on SBS2003
USB webcam 50-feet from computer
web forms: xForms or javascript forms: which one is the best?
Content disappearing after I hit a link?