1、用户表user有用户分类标签字段type,查出每个标签下男女sex各多少人
方式① 通过子查询的方式(数据更加简洁明了易懂)
select type,
(select count(*) from user where sex=1 and type=u.type) 男,
(select count(*) from user where sex=2 and type=u.type) 女
from user u
group by type;
方式②(数据不易懂)
select count(*),type,sex from user group by type,sex;