我们有如下表:
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 |
我想获得所有用户至少拥有其中之一的最大相似值
在此示例中,所有用户都有两个值. 6080和5300
结果应该是6080
我怎样才能做到这一点 ?
解决方法:
看起来像这样.您需要将结果限制为1,例如,对于mysql,您应在末尾使用limit 1;对于mssql,则应选择top 1 point .. etc等.
select point
from user
group by point
having count(*)=(select count(distinct user) from user)
order by point desc
标签:select,mysql
来源: https://codeday.me/bug/20191102/1993788.html