锁定老帖子 主题:某企业SQL面试题求解
精华帖 (0) :: 良好帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2012-05-13
zhouYunan2010 写道
我晕看到了varchar2还问事什么数据库? select * from( select * from score a where (select count(1) from score where course_id=a.course_id and score>=a.score)<=5 order by course_id,score desc) sc,student s,course c where sc.course_id=c.course_id and sc.student_id = s.student_id; 数据是前面仁兄的数据。
|
|
返回顶楼 | |
发表时间:2012-05-14
最后修改:2012-05-14
貌似是窗口函数的题 , 给出db2的实现 :
select * from ( select DENSE_RANK()over( partition by score.id order by score.score desc) as sort , stu.stuName , score.score, course.name from stu,score,course where stu.stuid = score.stuid and course.couid = score.scoreid order by score.name ) where sort < 6 -- 如果只要第三名 , 就是 sort = 3 |
|
返回顶楼 | |
发表时间:2012-05-14
加上学生性别,求第三名 怎么写
|
|
返回顶楼 | |
发表时间:2012-07-04
SELECT st.student_name,co.course_name,sc.score from student st, course co ,
(select student_id,course_id,score from (select student_id,course_id,score, RANK() OVER (ORDER BY score) rk from score) where rk<=5 ) as sc where st.student_id=sc.student_id and co.course_id=sc.course_id |
|
返回顶楼 | |