关闭

SQL 最大、第二大、第三大

标签: sql
2142人阅读 评论(1) 收藏 举报

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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:72712次
    • 积分:1159
    • 等级:
    • 排名:千里之外
    • 原创:44篇
    • 转载:9篇
    • 译文:0篇
    • 评论:20条
    文章分类
    最新评论