commit d4ac685b467c7d2beca2be3e89c35d6e322809c8 Author: zhang chengzhi <3144712872@qq.com> Date: Fri Jul 19 09:34:27 2024 +0800 日考二文件 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e403e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..680c2a9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + com.bwie + test_day2 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + diff --git a/sql/test_6_2.sql b/sql/test_6_2.sql new file mode 100644 index 0000000..431a83e --- /dev/null +++ b/sql/test_6_2.sql @@ -0,0 +1,90 @@ +/* + Navicat Premium Data Transfer + + Source Server : 106.54.199.209 + Source Server Type : MySQL + Source Server Version : 80400 + Source Host : 106.54.199.209:3306 + Source Schema : test_6_2 + + Target Server Type : MySQL + Target Server Version : 80400 + File Encoding : 65001 + + Date: 19/07/2024 09:05:01 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for stu_cou +-- ---------------------------- +DROP TABLE IF EXISTS `stu_cou`; +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; + +-- ---------------------------- +-- Records of stu_cou +-- ---------------------------- +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, 1, 4); +INSERT INTO `stu_cou` VALUES (5, 2, 5); +INSERT INTO `stu_cou` VALUES (6, 2, 6); +INSERT INTO `stu_cou` VALUES (7, 2, 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); +INSERT INTO `stu_cou` VALUES (11, 3, 11); +INSERT INTO `stu_cou` VALUES (12, 3, 2); + +-- ---------------------------- +-- Table structure for t_course +-- ---------------------------- +DROP TABLE IF EXISTS `t_course`; +CREATE TABLE `t_course` ( + `c_id` int NOT NULL AUTO_INCREMENT, + `c_name` varchar(255) 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; + +-- ---------------------------- +-- Records of t_course +-- ---------------------------- +INSERT INTO `t_course` VALUES (1, '云计算'); +INSERT INTO `t_course` VALUES (2, '大数据'); +INSERT INTO `t_course` VALUES (3, '全栈'); + +-- ---------------------------- +-- Table structure for t_student +-- ---------------------------- +DROP TABLE IF EXISTS `t_student`; +CREATE TABLE `t_student` ( + `s_id` int NOT NULL AUTO_INCREMENT, + `s_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, + `sex` varchar(255) 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, '小柳', '女'); +INSERT INTO `t_student` VALUES (11, '老七', '男'); + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/sql/日考二sql语句.sql b/sql/日考二sql语句.sql new file mode 100644 index 0000000..d3a778c --- /dev/null +++ b/sql/日考二sql语句.sql @@ -0,0 +1,28 @@ +-- 查询男生和女生各多少人 +-- 男生 +SELECT COUNT(t_student.s_id) FROM t_student WHERE t_student.sex = '男' + +-- 女生 +SELECT COUNT(t_student.s_id) FROM t_student WHERE t_student.sex = '女' + + +-- 查询男生和女生分别占总人数的比例 + + + + SELECT (SELECT COUNT(t_student.s_id) FROM t_student WHERE t_student.sex = '男') / (SELECT COUNT(t_student.s_id) FROM t_student) * 100 + + SELECT (SELECT COUNT(t_student.s_id) FROM t_student WHERE t_student.sex = '女') / (SELECT COUNT(t_student.s_id) FROM t_student) * 100 + + +-- 查询每门课程下的学生总人数。 + +SELECT + t_course.c_name, + COUNT( t_student.s_id ) +FROM + t_course + LEFT JOIN stu_cou ON t_course.c_id = stu_cou.c_id + LEFT JOIN t_student ON t_student.s_id = stu_cou.s_id + + GROUP BY t_course.c_id \ No newline at end of file diff --git a/理论/img.png b/理论/img.png new file mode 100644 index 0000000..5de0d33 Binary files /dev/null and b/理论/img.png differ