我们有如下表格:
user point
+-------+------+
| user1 | 6080 | // user1 has this value
+-------+------+
| user1 | 5300 |
+-------+------+
| user2 | 6080 | // user2 has this value
+-------+------+
| user3 | 6080 | // user3 has this value
+-------+------+
| user3 | 5300 |
+-------+------+
| user1 | 3520 |
+-------+------+
| user2 | 5300 |
+-------+------+
| user3 | 9800 |
我希望得到所有users
至少有一个这样的最大相似值
在此示例中,所有用户都有两个值。 6080
和5300
结果应为6080
我该怎么做?
答案 0 :(得分:4)
看起来像这样。您需要将结果限制为1,因此例如对于mysql,您应该在结尾使用限制1或者使用mssql选择前1点等等。
select point
from user
group by point
having count(*)=(select count(distinct user) from user)
order by point desc
答案 1 :(得分:0)
SELECT point, count(*) AS cnt FROM table GROUP BY point ORDER BY cnt DESC LIMIT 1