表:tb 字段: user status aaa 0 aaa 1 aaa 1 bbb 0 bbb 1 要求显示成这样的一个统计表: 用户 status总数 status=0个数 status=1个数 aaa 3 1 2 bbb 2 1 1 |
select `user` count(status) as totals from `mytable` where status = 0 group by user;
select `user` count(status) as totals from `mytable` where status = 1 group by user;
select count(status) from mytable where status = 0 group by user;
select count(status) from mytable where status = 1 group by user;