gpt4 book ai didi

MySQL仅选择列上具有最大值的行

转载 作者:行者123 更新时间:2023-11-30 00:33:43 25 4
gpt4 key购买 nike

我使用以下代码列出 jid 和计数。

Select jid,count(jid) as jidtime 
From Application
Group by jid;

enter image description here

但我还想显示 jid 和 max(jidtime),即 jid:4 jidtime:6

我尝试过,但失败了。需要一些帮助...

Select jid, max(jidtime) 
From (Select jid,count(jid) as jidtime From Application
Group by jid) AS T;

最佳答案

您可以使用order bylimit来做到这一点:

Select jid, count(jid) as jidtime 
From Application a
Group by jid
Order by count(jid) desc
Limit 1;

这将获取结果,按第二列对它们进行排序,然后将查询限制为第一行(应具有最高值)。

关于MySQL仅选择列上具有最大值的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22338122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com