Select Distinct id as personID, count(tid) as Sales
From salesTable
Group by personID;
当前的结果是:(我只需要显示最高销售额。)
personID | Sales
_____________________
1000 | 2
1020 | 1
1040 | 2
1060 | 1
1080 | 2
1140 | 1
1160 | 1
_________________
销售表如下所示:
id | tid
_________
1000|201
1020|202
1040|203
1000|204
1060|205
1080|206
1040|207
1080|208
1140|209
1160|210
我想要的结果应该是这样的:
personID | Sales
_____________________
1000 | 2
1040 | 2
1080 | 2
_________________
最佳答案
select id as personID
, count(tid) as Sales
From salesTable
group by
id
having count(tid) =
(
select max(Sales)
from (
select count(tid) as Sales
from salesTable
group by
id
) SubQueryAlias
)
关于mysql - SQL 仅显示计数函数的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15465537/