求个SQL查询100分

dupoutVIP 2008-09-25 10:01:36
我有一张表 table
id countID
1 2
2 2
3 3
4 1
5 3
6 2
7 3
8 1
现在要在这张表中 查询countID 字段 中出相同 记录出现次数的一个排行
在table中countID中有2 3 1 重复出现 重复次数最多的拍照前面
我想得到这样的一个查询
countid
2
3
1
...全文
85 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyqwan11112 2008-09-25
  • 打赏
  • 举报
回复
兄弟们太快了,刚写个测试数据,已回复就7个了!
nvrenchenling 2008-09-25
  • 打赏
  • 举报
回复
jf
云想慕尘 2008-09-25
  • 打赏
  • 举报
回复
select countid from tableName group by countid order by count(countid) desc
hyqwan11112 2008-09-25
  • 打赏
  • 举报
回复

--测试数据
create table 表(id int,countID int)
insert into 表
select 1,2 union all
select 2,2 union all
select 3,3 union all
select 4,1 union all
select 5,3 union all
select 6,2 union all
select 7,3 union all
select 8,1


select countID from 表
group by countID
order by count(countID) desc
Garnett_KG 2008-09-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 fcuandy 的回复:]
看到简单问题都想抢分,一抢就激动。我也手误

SQL codeselectcountidfromtbgroupbycountidorderbycount(*)desc
[/Quote]

haha.
113244 2008-09-25
  • 打赏
  • 举报
回复
LS正解。。

count函数统计排序。
fcuandy 2008-09-25
  • 打赏
  • 举报
回复
看到简单问题都想抢分,一抢就激动。我也手误

select countid from tb group by countid order by count(*) desc
fcuandy 2008-09-25
  • 打赏
  • 举报
回复
select countid from tb group by countid order by conut(*) desc
Garnett_KG 2008-09-25
  • 打赏
  • 举报
回复

---..
SELECT countid
FROM TableName
GROUP BY countid
ORDER BY COUNT(countid) DESC

Garnett_KG 2008-09-25
  • 打赏
  • 举报
回复


SELECT countid
FROM TableName
GROUP BY countid
ORDER BY COUNT(DISTINCT countid) DESC


34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧