考试前2分数和题解

考试前2分数的学生

http://www.nowcoder.com/questionTerminal/b83f8b0e7e934d95a56c24f047260d91

select id,name,score from
(select g1.id id,l.name name,g1.score score,
(select count(distinct g2.score) from grade g2 where g1.score<=g2.score and g1.language_id=g2.language_id)as rank
from grade g1,language l
where g1.language_id=l.id) as g
where rank<=2
/group by name 别多此一举/
order by name asc,score desc

根据前面的求最值,前几名,奇偶数的问题总结出一个通式(目的就是增加额外的"排名"列):
select t1.id,t1.type,t1.score,
(select count(distinct t2.score) from t t2 where t1.score<=t2.score and t1.type=t2.type) as rank
from t t1;

全部评论

相关推荐

点赞 评论 收藏
分享
08-15 01:16
Python
Java小萌新新萌小...:照片不用整这么大的 而且你的照片截歪了 你想找专业对口的 那普通话证写在这里其实没有什么必要 就是看着内容多点 而且里面字体大小也不一样 修改一下排版 有很多空间可以再利用一下 字大一点 不然现在这样观感不太好 再就是项目好好优化一下 加油
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务