码迷,mamicode.com
首页 > 数据库 > 详细

Mysql相关问题收集

时间:2018-03-26 22:33:43      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:targe   res   bad   mysql   title   set   AC   href   varchar   

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相关问题收集

标签:targe   res   bad   mysql   title   set   AC   href   varchar   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!