查询问题

datian8782 2008-09-12 10:34:33

一个表Tag标签表
id tagid topicid tagname
4 0 1979 国奥队
5 0 1979 奥运会
6 0 1980 女友
7 0 1980 偷看
8 0 1982 共享卡,会员卡,优惠卡,打折信息,卡号
9 0 1987 鸡
10 0 1988 上床
14 0 1990 女人
15 0 1990 男人


我要查询里面根据topicid的个数排序
显示效果
topicid tagname
1979 国奥队
1979 奥运会
1979 女友
1980 偷看
1980 共享卡,会员卡,优惠卡,打折信息,卡号
1987 鸡
1987 上床
1998 女人
1990 男人



...全文
40 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2008-09-12
  • 打赏
  • 举报
回复
错了,应该是这个.

select m.topicid, m.tagname from tag m ,
(select topicid , count(1) cnt from tag group by topicid) n
where m.topicid = n.topicid
order by n.cnt desc
dawugui 2008-09-12
  • 打赏
  • 举报
回复
select m.topicid, m.tagname from tag m ,
(select topicid , count(1) cnt from tag group by topicid) n
where m.tagid = n.tagid
order by n.cnt desc
dawugui 2008-09-12
  • 打赏
  • 举报
回复
select * from tag m ,
(select topicid , count(1) cnt from tag group by topicid) n
where m.tagid = n.tagid
order by n.cnt desc
水族杰纶 2008-09-12
  • 打赏
  • 举报
回复
select topicid ,tagname, count(*)C from tag group by topicid ,tagname order by C desc
dawugui 2008-09-12
  • 打赏
  • 举报
回复
6 0 1980 女友

1979 女友

这个是否错了?

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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