By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

Please help! I'm stuck!

P: 2
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
Share this Question
Share on Google+
1 Reply


P: 2
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.