--8.统计各系学生的人数,结果按升序排列; /*SELECT sdept,COUNT(*) FROM S WHERE sdept='CS'OR sdept='MA' OR sdept='IS' GROUP BY sdept;*/ 我只是按系名分组,但没有按学生的人数升序排列,请问怎么修改才能实现按学生人数排列
order by 默认是升序排列 order by <expression>desc 表示降序排列 /*SELECT sdept,COUNT(*) FROM S WHERE sdept='CS'OR sdept='MA' OR sdept='IS' GROUP BY sdept order BY COUNT(*)
试试这样写:
select Sdept,count(*) as 'count'
from Student
group by Sdept
order by count(*)
默认就是按照升序排列的,降序的话:
select Sdept,count(*) as 'count'
from Student
group by Sdept
order by count(*) desc