• Please help support our sponsors by considering their products and services.
    Our sponsors enable us to serve you with this high-speed Internet connection and fast webservers you are currently using at ADSM.ORG.
    They support this free flow of information and knowledge exchange service at no cost to you.

    Please welcome our latest sponsor Tectrade . We can show our appreciation by learning more about Tectrade Solutions
  • Community Tip: Please Give Thanks to Those Sharing Their Knowledge.

    If you receive helpful answer on this forum, please show thanks to the poster by clicking "LIKE" link for the answer that you found helpful.

  • Community Tip: Forum Rules (PLEASE CLICK HERE TO READ BEFORE POSTING)

    Click the link above to access ADSM.ORG Acceptable Use Policy and forum rules which should be observed when using this website. Violators may be banned from this website. This notice will disappear after you have made at least 3 posts.

SQL query with multiple count(*) statements

darkhorse

ADSM.ORG Member
#1
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,
 

darkhorse

ADSM.ORG Member
#2
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
 

marclant

ADSM.ORG Moderator
#3
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
 

Advertise at ADSM.ORG

If you are reading this, so are your potential customer. Advertise at ADSM.ORG right now.

UpCloud high performance VPS at $5/month

Get started with $25 in credits on Cloud Servers. You must use link below to receive the credit. Use the promo to get upto 5 month of FREE Linux VPS.

The Spectrum Protect TLA (Three-Letter Acronym): ISP or something else?

  • Every product needs a TLA, Let's call it ISP (IBM Spectrum Protect).

    Votes: 10 16.7%
  • Keep using TSM for Spectrum Protect.

    Votes: 35 58.3%
  • Let's be formal and just say Spectrum Protect

    Votes: 9 15.0%
  • Other (please comement)

    Votes: 6 10.0%

Forum statistics

Threads
31,185
Messages
132,720
Members
21,341
Latest member
sskkss
Top