Re: Multiple counts on the same column
Like this?
select book_name,
count(if(rating=1, 1, null)) as "POOR",
count(if(rating=2,1,null)) as "Average",
count(if(rating=3,1,null)) as "Good",
count(if(rating=4,1,null)) as "Great"
from rating
group by book_name
order by book_name;
+----------------+------+---------+------+-------+
| book_name | POOR | Average | Good | Great |
+----------------+------+---------+------+-------+
| Javascript | 0 | 1 | 0 | 0 |
| SQL Cookbook | 0 | 1 | 1 | 1 |
| Visual Basic 6 | 1 | 0 | 1 | 0 |
+----------------+------+---------+------+-------+
Subject
Written By
Posted
Re: Multiple counts on the same column
April 07, 2008 12:10PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.