将数据量分组在一起并创建动态amt列

时间:2011-08-12 20:18:37

标签: mysql

我有一个像这样的mysql数据库:

id - join_id - bool
1 - 32 - 1
2 - 32 - 0
3 - 32 - 1
4 - 32 - 1

我想查询一下:

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 bool are 32 and 0);

任何关键词或名称都会有所帮助。

1 个答案:

答案 0 :(得分:1)

我认为这就是你要找的东西:

SELECT join_id, bool, COUNT(id) AS amount FROM mytable GROUP BY join_id,bool