sql - 如何从中间有最大计数的表中获取 eid?
问题描述
我有一个具有以下结构的表员工:
Id. Mid Salary
1 20 200
2 20 3000
3 30 200
4 34 4000
5 30 300
6 30 400
1 23 440
1 24 333
2 21 3
我想得到如下结果:
Id Mid
1 3
解决方案
使用前 1
select top 1 id,count(*) as cnt
from table
group by id
order by cnt desc
如果您需要领带,请使用with ties
select top 1 with ties id,count(*) as cnt
from table
group by id
order by cnt desc
推荐阅读
- python - 如何对涉及两个数据帧的条件的熊猫行迭代进行矢量化?
- generics - 将具有泛型类型参数的结构转换为特定类型
- ajax - tabView: event.getTab() 在 Mojarra 2.3 中总是为空 - 替代方案?
- web-scraping - 为什么每当从网站上抓取信息时都会出现此错误?
- python - 尝试从邮递员发帖时收到一条错误消息,指出“没有名为收容所的列”
- javascript - 如何在 map 函数中累积值并存储在 useState 中
- linux - 将 Windows .exe 文件转换为二进制内容
- docker - Docker:除了 docker-compose.yml 之外,如何使用 Dockerfile
- google-analytics - Google Ads 报告中未显示 GA 数据
- iframe - 如何在 javascript 中从 iframe 获取 html 代码