读书人

关于查询排序有关问题

发布时间: 2012-01-30 21:15:58 作者: rapoo

关于查询排序问题
我的表是这样的
id title type----title是文章标题 type是类别
1 哈哈 公告
2 呵呵 新闻
3 嘿嘿 新闻
4 由于 公告
5 威尔 公告
6 噢噢 动态

我现在想要这样的排序,就是按文章的量来排序
比如结果:
第一:公告
第二:新闻
第三:动态

请问select语句该怎么写
请大家指点
谢谢

[解决办法]
select counttype
from ( select counttype = count(type)
from [表] group by type) as tmp
order by tmp.counttype desc
[解决办法]
select type,count(*) from 表 group by typeorder by count(*) desc

读书人网 >SQL Server

热点推荐