我的记录是:
name | id | AVG(point) as point
a | 1 | 6
b | 2 | 6
c | 3 | 5
d | 4 | 5
e | 5 | 4
f | 6 | 3
g | 7 | 2
如何选择以下记录:
1.我想选择前3条记录,结果如下:
name | id | AVG(point) as point
a | 1 | 6
b | 2 | 6
c | 3 | 5
d | 4 | 5
e | 5 | 4
2.我想选择不进入前3名的记录,结果如下:
name | id | AVG(point) as point
f | 6 | 3
g | 7 | 2
我该怎么办?
最佳答案
有多种方法可以实现这些目的。这是使用 in
和 not in
的例子。
对于前 3 个,您可以使用 in
:
select *
from yourtable
where point in (select distinct point
from yourtable
order by 1 desc
limit 3)
对于其余部分,请使用 not in
代替:
select *
from yourtable
where point not in (select distinct point
from yourtable
order by 1 desc
limit 3)
其他方法包括 exists
和 not contains
以及 distinct
和 joins
。
关于mysql - 如何在mysql中选择所有重复记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35835145/