954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Get occurrences of a record

hey guys, i dont suppose you know how i can go from:

id.............result
----------------------
1..............Pass
1..............Pass
1..............Fail
1..............Pass
1..............Fail
2..............Pass
2..............Pass
2..............Fail

to this table:

id...........pass......fail
1............3.........2
2............2.........1

my current query is simply

select id, result from results

I just want to display the total number of occurrences of a result and display them under appropriate headings...I tried performing a union on 2 separate select statements, but it just stacks results on top of one another...

thanks for any help

2eXtreme
Light Poster
35 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 
SELECT id, COUNT(NULLIF( result, 'Fail' )) Passes, COUNT(NULLIF( result, 'Pass' )) Fails
FROM results
GROUP BY id
ORDER BY id
peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You