写一个SQL: 找到每个班级内年龄最小的同学的学号

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

DROP TABLE IF EXISTS `students`;
CREATE TABLE `students` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增id',
  `student_no` varchar(16) NOT NULL DEFAULT '0' COMMENT '学号',
  `class` tinyint(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '班级',
  `age` int(10) NOT NULL DEFAULT '0' COMMENT '年龄',
  `create_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COMMENT='学生表';


BEGIN;
INSERT INTO `students` VALUES (1, 'a1101', 1, 3, 2, '2020-04-04 07:39:44');
INSERT INTO `students` VALUES (2, 'a1102', 1, 4, 3, '2020-04-04 07:39:44');
INSERT INTO `students` VALUES (3, 'a1103', 1, 5, 3, '2020-04-04 07:39:45');
INSERT INTO `students` VALUES (4, 'a1104', 1, 6, 33, '2020-04-04 07:39:46');
INSERT INTO `students` VALUES (5, 'a1105', 2, 7, 33, '2020-04-04 07:39:46');
INSERT INTO `students` VALUES (6, 'a1106', 2, 8, 2, '2020-04-04 07:39:47');
INSERT INTO `students` VALUES (7, 'a1107', 2, 9, 2, '2020-04-04 07:39:25');
INSERT INTO `students` VALUES (8, 'a1108', 2, 10, 11, '2020-04-04 07:40:08');
INSERT INTO `students` VALUES (9, 'a1109', 3, 2, 22, '2020-04-04 07:40:09');
INSERT INTO `students` VALUES (10, 'a1110', 3, 5, 22, '2020-04-04 07:40:09');
INSERT INTO `students` VALUES (11, 'a1101', 3, 4, 22, '2020-04-04 07:40:10');
INSERT INTO `students` VALUES (12, 'a1102', 3, 7, 222, '2020-04-04 07:40:12');
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;

写一个SQL: 找到每个班级内年龄最小的同学的学号

select student_no 
from students a 
where a.age=(select min(age) from students b where a.class=b.class);
select *  
from   students t
where not exists(select 1 from   students where class=t.class and  age<t.age) 

写一个SQL: 每个班级内年龄最大的三位学生的学号

SELECT * 
FROM students e1 WHERE ( SELECT count( 1 ) FROM students e2 WHERE e2.class = e1.class AND e2.age >= e1.age ) <= 3 /*这里的数值表示你想取前几名*/  
ORDER BY class, age DESC;

https://www.cnblogs.com/hxzblog/p/7307537.html