首页 > 数据库技术 > 详细

sql查询2

时间:2014-03-17 10:56:59      阅读:334      评论:0      收藏:0      [点我收藏+]

查询各科成绩前三名的记录:(不考虑成绩并列情况

sc表,student表,course表

比如某一科的前三名

 

bubuko.com,布布扣
selcet score ,c_id from sc where c_id=1 order by score limit0,3;
bubuko.com,布布扣

 

于是

bubuko.com,布布扣
select  from sc  as s1 where s1.score in
(select score from sc where s1.c_id=c_id group by c_id order by score desc limit0,3);
bubuko.com,布布扣

但是这个出了问题,limit 不能有in,看网上说法可以再套一个select,但是有个问题是s1.c_id不认识了

用top 3在mysql又不能用

sql查询2,布布扣,bubuko.com

sql查询2

原文:http://www.cnblogs.com/bashala/p/3604348.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!