首页 > 数据库技术 > 详细

Mysql相关问题收集

时间:2018-03-26 21:52:03      阅读:217      评论:0      收藏:0      [点我收藏+]

1.查询每个班级的前三名

DROP TABLE IF EXISTS `sc`;
CREATE TABLE `sc` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) CHARACTER SET utf8 DEFAULT NULL,
  `class` varchar(200) CHARACTER SET utf8 DEFAULT NULL,
  `score` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

 
insert into sc values (1,badkano,一年一班,100);
insert into sc values (2,百度知道团长,一年一班,99);
insert into sc values (3,du小短,一年一班,95);
insert into sc values (4,du小小动,一年一班,97);
insert into sc values (5,du小智,一年一班,80);
insert into sc values (6,吕布,一年二班,67);
insert into sc values (7,赵云,一年二班,90);
insert into sc values (8,典韦,一年二班,89);
insert into sc values (9,关羽,一年二班,70);
insert into sc values (10,马超,一年二班,98);

result:

select 
    * 
from sc t
where 
    (select count(1)+1 from sc where class=t.class and score>t.score)
    <= 3

 

 

 

https://zhidao.baidu.com/question/117048828.html

Mysql相关问题收集

原文:https://www.cnblogs.com/hongdada/p/8654174.html

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