MySQL查询同一列不同值出现次数

即条件求和,共三种方式
select sum(value = 'aaa') from test;
select sum(if(value = 'aaa', 1, 0)) from test;
select count(if(value = 'aaa', 1, null)) from test;
注意:使用count时if最后一个参数要写成null,写成0会统计失败

posted @ 2022-10-09 16:59  我是橘子  阅读(186)  评论(0编辑  收藏  举报