注册 登录
编程论坛 SQL Server论坛

统计各系学生的人数,结果按升序排列;要怎么修改才正确

jiushiwo 发布于 2007-04-19 15:26, 5950 次点击
--8.统计各系学生的人数,结果按升序排列;
/*SELECT sdept,COUNT(*)
FROM S
WHERE sdept='CS'OR sdept='MA' OR sdept='IS'
GROUP BY sdept;*/
我只是按系名分组,但没有按学生的人数升序排列,请问怎么修改才能实现按学生人数排列
8 回复
#2
bygg2007-04-19 15:40
排序不是用order by 吗?group....这个是分类吧??
#3
棉花糖ONE2007-04-19 16:03
默认是按升序排列的啊
#4
jiushiwo2007-04-19 22:44
SELECT sdept,COUNT(*)
FROM S
GROUP BY sdept
ORDER BY COUNT(*);
这样改就行了
#5
zhangbo851282007-04-23 16:58

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(*)

#6
ldy6632007-05-04 16:03
select sdept,COUNT(*)
from S
where sdept='CS' or sdept='MA' or sdept='IS'
group by sdept
order by COUNT(*);
#7
zhangbo851282007-05-08 10:10
hehe
#8
zhangbo851282007-05-08 10:11
怎么样啊
不见有什么反映啊
#9
abc1282023-10-18 15:51
试试这样写:
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
1