1. 程式人生 > 其它 >sql筆試題:每個班級中成績最高的女生分別是誰?

sql筆試題:每個班級中成績最高的女生分別是誰?

技術標籤:面試題·mysql

昨天筆試遇到一個寫sql的題目

題目是,每個班級中成績最高的女生分別是誰?



SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student`  (
  `name` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `num` int NULL DEFAULT NULL,
  `class` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `sex` tinyint(1) NULL DEFAULT NULL,
  `score` int NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES ('張三', 1, '一班', 0, 97);
INSERT INTO `student` VALUES ('李四', 2, '一班', 0, 99);
INSERT INTO `student` VALUES ('小麗', 3, '一班', 1, 96);
INSERT INTO `student` VALUES ('王二', 1, '二班', 0, 95);
INSERT INTO `student` VALUES ('麻子', 2, '二班', 0, 99);
INSERT INTO `student` VALUES ('小娜', 3, '二班', 1, 87);
INSERT INTO `student` VALUES ('小萱', 4, '一班', 1, 98);
INSERT INTO `student` VALUES ('小媛', 4, '二班', 1, 98);
INSERT INTO `student` VALUES ('小四', 4, '一班', 1, 99);

SET FOREIGN_KEY_CHECKS = 1;