这里看到一个SQL题目:查询学生总成绩的前三名,给出MySQL和Oracle的写法

namecoursegrade
nickyuwen88
jackshuxue95
nickshuxue68
jackyuwen96
susanyuwen100
susanshuxue95
leeyuwen100
leeshuxue95
zhangyuwen58
zhangshuxue91

MySQL使用LIMIT关键字:

SELECT name
FROM student_grade
GROUP BY name
ORDER BY sum(grade) DESC
LIMIT 0,3

Oracle使用ROWNUM关键字

select name FROM(
    SELECT name
    FROM student_grade
    GROUP BY name
    ORDER BY sum(grade) DESC
)WHERE rownum <=3;

标签: SQL

添加新评论