一条sql语句能不能统计两个结果

来源:百度知道 编辑:UC知道 时间:2024/06/27 14:44:07
一个学生表,统计总人数和其中的女生人数
"select count(*) from 学生表 union select count(*) from 学生表 where 性别 = '女'" 正解,但是为什么在返回结果中,统计"性别 = '女'"的结果先返回而全部学生数后返回,如下

COUNT(*)
1 601
2 1206

select count(*) from 学生表 union select count(*) from 学生表 where 性别 = '女'

显然能达到你的要求
使用count

当然可以:select count(*),count(性别) from 学生表 where 性别='女'

select count(*),性别 from product group by 性别

正常的话 出来2条记录,一条 男 ;一条 女 ;