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 | +----------------+------+---------+------+-------+
IF(expression, return this if expression is true, return this if expression is false)
No comments:
Post a Comment