SQL 最大、第二大、第三大

select 

id,

age = (select max(age) from test where age <> (select max(age) from test))

from test

group by id,age 

order by id desc ,age desc

 

select 

id,

age = (select max(age) from test where age <> (select max(age) from test) and age <> (select Distinct age = (select max(age) from test where age <> (select max(age) from test)) from test))

from test

group by id,age 

order by id desc ,age desc

阅读更多
文章标签: sql
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

SQL 最大、第二大、第三大

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭