SQL query with multiple count(*) statements

darkhorse

ADSM.ORG Member
Joined
Feb 22, 2005
Messages
59
Reaction score
0
Points
0
Website
Visit site
This must be easy. just can't get the syntax right.
I want to count multiple results from the same Table.
I am trying to count(*) failed completed pending , status from the events Table but I need to able to have different where statements from each count(*).

Any assistance would be appreciated,
 
So something like
select count(*) as "Completed Schedules" from events where status='Completed' and scheduled_start>= current_timestamp - 24 hours
and
select count(*) as "Pending Schedules" from events where status='Pending' and scheduled_start>= current_timestamp - 24 hours
and
select count(*) as "Missed Schedules" from events where status='Missed' and scheduled_start>= current_timestamp - 24 hours

OUTPUT example

Resulted Backups

Completed Schedules-----Pending Schedules-----Missed Schedules
---------542-------------------------25----------------------50
 
You're doing it the hard way. You could do it this way:
SQL:
select status,count(*) as COUNT from events where status in ('Completed','Pending' ,'Missed' ) and scheduled_start>= current_timestamp - 24 hours group by status
 
Thanks Marclant for the reply, knew there had to an more consise approach. Will try this in morning. :)
 
Back
Top