[求助]如何找出某个相同值对多的数据?具体问题如下

readings 2008-01-21 11:17:30
有TABLE1,其中有字段id,pinglunid(int型),而pinglunid为另一个表的id的编号,如何写一SQL语句,能查询出pinglunid最多的一个?
...全文
59 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2008-01-21
  • 打赏
  • 举报
回复
--不知道你表2是否有pinglunid?对应关系用下面哪个?

select top 1 pinglunid , count(*) cnt from tb1,tb2 where tb1.pinglunid = tb2.id
group by pinglunid order by cnt desc

select top 1 pinglunid , count(*) cnt from tb1,tb2 where tb1.pinglunid = tb2.pinglunid
group by pinglunid order by cnt desc
yangjiexi 2008-01-21
  • 打赏
  • 举报
回复

select pinglunid,count(1) num
from table1
group by pinglunid
dawugui 2008-01-21
  • 打赏
  • 举报
回复
select top 1 pinglunid , count(*) cnt from tb1,tb2 where tb1.pinglunid = tb2.id
group by pinglunid order by cnt desc
tim_spac 2008-01-21
  • 打赏
  • 举报
回复
select top 1 pinglunid
from table1
group by pinglunid
order by count(1) desc
readings 2008-01-21
  • 打赏
  • 举报
回复
补充:我的意思是怎样查询出pinglunid相同的累计数最多的一个pinglunid?

34,837

社区成员

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

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