我已经尝试这样做几个小时了,但我一直得到空结果。到目前为止,我通过运行查询得到了下表
按用户从 dbtable 组中选择计数(帖子)
user | posts
_____________
a | 3
b | 7
c | 2
d | 1
e | 1
如何在不使用 max()/greatest() 甚至 LIMIT 函数的情况下显示用户的最大帖子数。我运行上述查询的原始表包含所有帖子以及提交每个帖子的用户的列表,我只是将它们分组。
最佳答案
select * from
(
select user,count(posts) cnt from dbtable
group by user
) t1
left join
(
select user,count(posts) cnt from dbtable
group by user
) t2 on (t1.user<>t2.user) and (t1.cnt<t2.cnt)
where t2.cnt is null
关于sql - 不使用 Max()/Greatest() 函数查找最大组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16099145/