SQL SERVER 根据某列的值的重复次数排序
table1:iddepartment1A2B3C4A5A6C查询结果按a、b、c的出现次数由大到小排序结果应该是如:A,C,B.....
table1:
id department
1 A
2 B
3 C
4 A
5 A
6 C
查询结果按a、b、c的出现次数由大到小排序
结果应该是如: A , C , B .. 展开
id department
1 A
2 B
3 C
4 A
5 A
6 C
查询结果按a、b、c的出现次数由大到小排序
结果应该是如: A , C , B .. 展开
2013-07-11
展开全部
select (case department when 'A' then 'A' when 'B' then 'B' when 'C' then 'C' end) as department,count(department) as f1 from tbele group by department order by count(department) desc
结果
department f1
A 3
C 2
B 1
结果
department f1
A 3
C 2
B 1
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-11
展开全部
select * from (
select department, count(*)as count
from table1
group by department
) order by count desc
select department, count(*)as count
from table1
group by department
) order by count desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询