Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning two counts in a query 1

Status
Not open for further replies.

gregc73

Technical User
Dec 16, 2003
5
US
I am trying to write a query that would return two COUNT values. Basically, I have a table that contains JOBGROUP, JOBNAMES and STATUS. There are many JOBNAMES for each JOBGROUP. The status field can either be SUCCESS or NONE.

So the table looks like this:
JOBGROUP JOBNAME STATUS
A A1 NONE
A A2 NONE
A A3 SUCCESS
B B1 NONE
B B2 NONE
B B3 NONE

What I want to return is the following:

JOBGROUP TOTAL_JOBS TOTAL_SUCCESS
A 3 1
B 3 0


Any Ideas? Sorry if this is basic, but I'm novice at SQL.
 
Code:
SELECT JOBGROUP, COUNT(JOBNAME) AS Total_Jobs, 
SUM(CASE WHEN Status = 'Success' THEN 1 ELSE 0 END) AS Total_success 
FROM YourTable GROUP BY JOBGROUP
Does this get it for you?

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top