468,316 Members | 2,029 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

Please help! I'm stuck!

I have a table that looks something like:

ID Command ExitCode
----------------------------------
1 notepad 0
2 notepad 0

I am trying to write a query that will return the number of successes and exit codes for each command. I can do this perfectly in two queries but I need to do this in a single query. I'm very new to SQL and just started reading about joins yesterday. I haven't been able to accomplish what I want. The two queries that I've been using are:

SELECT COUNT(ID) AS [Failure count], Command
FROM table1
WHERE ExitCode<>0
GROUP BY Command
ORDER BY [Failure count] DESC

This returns:

Failure Count Command
-------------------------------------
10 Notepad
5 Wordpad

SELECT COUNT(ID) AS [Success count], Command
FROM table1
WHERE ExitCode=0
GROUP BY Command
ORDER BY [Success count] DESC

This returns:

Success Count Command
---------------------------------------
500 Notepad
302 Wordpad


I am trying to write a query that will combine those two results and produce the following:

Failure Count Command Success Count
------------------------------------------------------------
10 Notepad 500
5 Wordpad 302

Is there anyone out there who may be able to help? Thanks in advance, it's very much appreciated!
Nov 20 '08 #1
1 1059
CASE allowed me to accomplish what I was after.
Nov 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Alan Bashy | last post: by
7 posts views Thread by tyler_durden | last post: by
23 posts views Thread by Jason | last post: by
5 posts views Thread by tabani | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.