[英]How to get number of rows per group by partition in mysql?
In mysql, if you have a table like this 在mysql中,如果有这样的表
A | B
------
1 | 0
1 | 0
1 | 0
2 | 0
2 | 0
3 | 0
3 | 0
3 | 0
3 | 0
How can you turn it into 你怎么能变成
A | c
------
1 | 3
2 | 2
3 | 4
c is the count column, so there was 3 1's, 2 2's and 4 3's. c是计数列,因此有3 1's,2 2's和4 3's。
Does anyone know how to do this? 有谁知道如何做到这一点?
Thanks. 谢谢。
You can do it like this: 您可以这样做:
SELECT A, count(*) as c FROM table GROUP BY A;
check this SQLFiddle to play around with it: http://sqlfiddle.com/#!2/36c59/1 检查此SQLFiddle并对其进行处理: http ://sqlfiddle.com/#!2/36c59/1
select count(A) from table group by A;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.