esport Posted April 23, 2008 Share Posted April 23, 2008 Hi Guys, I was wonder how to acheive multiple COUNTS in 1 query. For example, I have a user_rating table, id, user_id, rating i want to count the different ratings, say A and B for example. Can I do this in 1 query? Thanks Daniel Quote Link to comment Share on other sites More sharing options...
fenway Posted April 23, 2008 Share Posted April 23, 2008 You can, but you have to cheat with SUM: sum( if( rating = 'A', 1, 0 ) ) as ratingA, sum( if( rating = 'B', 1, 0 ) ) as ratingB, Quote Link to comment Share on other sites More sharing options...
esport Posted April 24, 2008 Author Share Posted April 24, 2008 Thanks heaps, worked a treat. So is that the only way to achieve this? Otherwise do multiple queries with COUNT and WHERE clause. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.