Grouping amounts of data together and creating a on-the-fly amt column
I have a mysql database like this:
id - join_id - bool
1 - 32 - 1
2 - 32 - 0
3 - 32 - 1
4 - 32 - 1
I would like to query this:
join_id - bool (- amount)
32 - 1 - 3 (aka there are 3 instances where the join_id and bool are 32 and 1);
32 - 0 - 1 (aka there is 1 instances where the join_id and boo开发者_StackOverflowl are 32 and 0);
Any key words, or names would really helpful.
This is what you are looking for I think:
SELECT join_id, bool, COUNT(id) AS amount FROM mytable GROUP BY join_id,bool
精彩评论