我们有如下表格:

  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至少有一个
在这个示例中,所有用户都有两个值。60805300
结果应6080
我该怎么做?

最佳答案

会像这样。您需要将结果限制为1,例如对于mysql,您应该在末尾使用limit 1,对于mssql,请选择top 1 point。等等。

select point
from user
group by point
having count(*)=(select count(distinct user) from user)
order by point desc

10-08 11:11