SQL查询语句问题

xiaoziguo1 2011-05-19 10:10:16
问题:怎么查找回复最多的5个帖子 ,帮帮忙
1 --创建评论表
2
3 create table Comment
4
5 (
6
7 ID int identity(1,1) not null primary key,
8
9 InvitationID int not null,
10
11 CommentContent text not null
12
13 )
14
15
16
17 --创建帖子表
18
19 create table Invitation
20
21 (
22
23 ID int identity(1,1) not null primary key,
24
25 CategoryName varchar(50) not null,
26
27 InvitationTitle varchar(50) not null,
28
29 InvitationContent text not null
30
31 )
问题:怎么查找回复最多的5个帖子 ,帮帮忙
...全文
45 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoziguo1 2011-05-19
  • 打赏
  • 举报
回复
问题解决了,,谢谢 josy
xiaoziguo1 2011-05-19
  • 打赏
  • 举报
回复
count(1)什么意思
快溜 2011-05-19
  • 打赏
  • 举报
回复
select a.*
from Invitation a
inner join (select top 5 InvitationID from Comment group by InvitationID order by count(1) desc) b on a.InvitationID=b.InvitationID
百年树人 2011-05-19
  • 打赏
  • 举报
回复
select *
from Invitation
where id in(select top 5 InvitationID from Comment group by InvitationID order by count(1) desc)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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