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 Link to comment https://forums.phpfreaks.com/topic/102517-solved-count/ 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, Link to comment https://forums.phpfreaks.com/topic/102517-solved-count/#findComment-524882 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. Link to comment https://forums.phpfreaks.com/topic/102517-solved-count/#findComment-525746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.