首页 > mysql查询同一个字段的三个count值

mysql查询同一个字段的三个count值

一个字段rvalue有三个值 想用一个sql语句同时输出三个count值
我只会写一个的:select COUNT(*) from room where rvalue = '入住'


如果用count的话,三个字段的count值会是一样。如果有按条件统计可以考虑用case和sum来配合使用。
比如
select sum(case gender when 'female' then 1 else 0 end) as Women, sum(case gender when 'male' then 1 else 0 end) as Men from users


SELECT `rvalue`, COUNT( 1 ) FROM `room` GROUP BY `rvalue`
【热门文章】
【热门文章】