学生信息表,如下: ID SEX SCORE YEAR 1 男 88 2007 2 女 87 2008 3 男 89 2006 4 女 99 2009 5 男 54 2007 6 女 56 2008
要求统计出学生总人数,男生总人数,女生总人数 小弟是在搞不定,求答案!谢谢select count(*) from student; select count(*) from student where sex='男'; select count(*) from student where sex='女';
SQL code:
select sex,count(*) from student group by sex select count(*) as 总人数 from student
不是用两条语句 select (select count(*) from student) as total,(select count(*) from student where sex='男') as mens,(select count(*) from student where sex='女') as womens from student;