如何在sql中的列中获得最多2个值

时间:2018-01-05 07:29:24

标签: mysql sql

例如

1
10
8
9
5

我应该在给定列中找到最多两个值,因为在sql查询中答案是10和9

1 个答案:

答案 0 :(得分:8)

您可以使用order bylimit

select col
from t
order by col desc
limit 2;

如果列可能有重复项,则使用select distinct col