

-- 3.查询男生和女生各多少人。（15分）
SELECT sex,count(*) FROM t_student GROUP BY sex

-- 4.	查询男生和女生分别占总人数的比例。（20分）
SELECT sex,ROUND(count(*)/(SELECT count(*) FROM t_student),2) FROM t_student GROUP BY sex 

-- 5.查询每门课程下的学生总人数。（15分）
SELECT
	c.c_name,count(*)
FROM
	t_student s
	LEFT JOIN stu_cou sc on s.s_id = sc.s_id
	LEFT JOIN t_course c on c.c_id = sc.c_id GROUP BY c.c_id
	
	
	
	
CREATE TABLE `t_student`  (
  `s_id` int NOT NULL AUTO_INCREMENT,
  `s_name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  `sex` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  PRIMARY KEY (`s_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- Records of t_student
-- ----------------------------
INSERT INTO `t_student` VALUES (1, '张三', '男');
INSERT INTO `t_student` VALUES (2, '李四', '男');
INSERT INTO `t_student` VALUES (3, '王五', '男');
INSERT INTO `t_student` VALUES (4, '赵六', '男');
INSERT INTO `t_student` VALUES (5, '田七', '男');
INSERT INTO `t_student` VALUES (6, '崔八', '男');
INSERT INTO `t_student` VALUES (7, '春兰', '女');
INSERT INTO `t_student` VALUES (8, '夏竹', '女');
INSERT INTO `t_student` VALUES (9, '秋叶', '女');
INSERT INTO `t_student` VALUES (10, '冬梅', '女');


CREATE TABLE `t_course`  (
  `c_id` int NOT NULL AUTO_INCREMENT,
  `c_name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  PRIMARY KEY (`c_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;


INSERT INTO `t_course` VALUES (1, '语文');
INSERT INTO `t_course` VALUES (2, '数学');
INSERT INTO `t_course` VALUES (3, '英语');



CREATE TABLE `stu_cou`  (
  `sc_id` int NOT NULL AUTO_INCREMENT,
  `c_id` int NULL DEFAULT NULL,
  `s_id` int NULL DEFAULT NULL,
  PRIMARY KEY (`sc_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;


INSERT INTO `stu_cou` VALUES (1, 1, 1);
INSERT INTO `stu_cou` VALUES (2, 1, 2);
INSERT INTO `stu_cou` VALUES (3, 1, 3);
INSERT INTO `stu_cou` VALUES (4, 2, 4);
INSERT INTO `stu_cou` VALUES (5, 2, 6);
INSERT INTO `stu_cou` VALUES (6, 2, 5);
INSERT INTO `stu_cou` VALUES (7, 3, 7);
INSERT INTO `stu_cou` VALUES (8, 3, 8);
INSERT INTO `stu_cou` VALUES (9, 3, 9);
INSERT INTO `stu_cou` VALUES (10, 3, 10);

	
	