首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于查询排序有关问题

2012-01-30 
关于查询排序问题我的表是这样的idtitletype----title是文章标题type是类别1哈哈公告2呵呵新闻3嘿嘿新闻4

关于查询排序问题
我的表是这样的
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

热点排行