From 577a5afee296e9841e11e757dd56a64d149b85eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8F=AD=E9=98=B3=E4=B8=BD?= <2431466589@qq.com> Date: Sun, 12 Mar 2023 23:58:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=83=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3\346\254\241\344\275\234\344\270\232.txt" | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 "37 \346\217\255\351\230\263\344\270\275/20230312 \347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.txt" diff --git "a/37 \346\217\255\351\230\263\344\270\275/20230312 \347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.txt" "b/37 \346\217\255\351\230\263\344\270\275/20230312 \347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.txt" new file mode 100644 index 0000000..811a0d7 --- /dev/null +++ "b/37 \346\217\255\351\230\263\344\270\275/20230312 \347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.txt" @@ -0,0 +1,105 @@ +```mysql +CREATE database hollow charset utf8; +use hollow; +-- 按图片所给的数据进行数据表的建立和数据插入,然后进行以下查询操作 +CREATE table stuinfo( +stuNO varchar(20), +stuName varchar(20), +stuAge int, +stuAddress varchar(20), +stuSeat int, +stuSex int +); +INSERT INTO `stuinfo` VALUES ('s2501', '张秋利', 20, '美国硅谷', 1, 1); +INSERT INTO `stuinfo` VALUES ('s2502', '李斯文', 18, '湖北武汉', 2, 0); +INSERT INTO `stuinfo` VALUES ('s2503', '马文才', 22, '湖南长沙', 3, 1); +INSERT INTO `stuinfo` VALUES ('s2504', '欧阳俊雄', 21, '湖北武汉', 4, 0); +INSERT INTO `stuinfo` VALUES ('s2505', '梅超风', 20, '湖北武汉', 5, 1); +INSERT INTO `stuinfo` VALUES ('s2506', '陈旋风', 19, '美国硅谷', 6, 1); +INSERT INTO `stuinfo` VALUES ('s2507', '陈风', 20, '美国硅谷', 7, 0); +CREATE TABLE stuexam( +examNO int, +stuNO varchar(20), +writtenExam int, +labExam int +); +INSERT INTO `stuexam` VALUES (1, 's2501', 50, 70); +INSERT INTO `stuexam` VALUES (2, 's2502', 60, 65); +INSERT INTO `stuexam` VALUES (3, 's2503', 86, 85); +INSERT INTO `stuexam` VALUES (4, 's2504', 40, 80); +INSERT INTO `stuexam` VALUES (5, 's2505', 70, 90); +INSERT INTO `stuexam` VALUES (6, 's2506', 85, 90); +-- 1.查询学生信息表(stuinfo)中所有列信息,给每列取上中文名称 +SELECT stuNO 学号,stuName 姓名,stuAge 年龄,stuAddress 地址,stuSeat 座位,stuSex 性别 FROM stuinfo; +-- 2.查询学生信息表(stuinfo)中的姓名,年龄和地址三列的信息 +select stuName 姓名,stuAge 年龄,stuAddress 地址 from stuinfo; +-- 3.查询学生分数表(stuexam)中的学号,笔试和机试三列的信息,并为这三列取中文名字 +select stuNO 学号,writtenExam 笔试,labExam 机试 from stuexam; +-- 5.查询学生分数表(stuexam)中的学生的学号,笔试,机试以及总分这四列的信息 +select stuNO 学号,writtenExam 笔试,labExam 机试 , (writtenExam+labExam) 总分 from stuexam; +-- 6.查询学生信息表(stuInfo)中学生来自哪几个地方 +select DISTINCT stuAddress 地址 from stuinfo; +-- 7.查询学生信息表(stuInfo)中学生有哪几种年龄,并为该列取对应的中文列名 +select DISTINCT stuAge 年龄 from stuinfo; + +-- 8.查询学生信息表(stuInfo)中前3行记录 +select * from stuinfo limit 3 ; +-- 9.查询学生信息表(stuInfo)中前4个学生的姓名和座位号 +select stuName 姓名,stuNO 学号 from stuinfo limit 4; + +-- 11.将地址是湖北武汉,年龄是20的学生的所有信息查询出来 +select * from stuinfo left join stuexam on stuinfo.stuNO=stuexam.stuNO where stuAddress='湖北武汉' and stuAge=20; +-- 12.将机试成绩在60-80之间的信息查询出来,并按照机试成绩降序排列 +select * from stuexam where labExam BETWEEN 60 and 80 ORDER By labExam desc; + +-- 13.查询来自湖北武汉或者湖南长沙的学生的所有信息 +select * from stuinfo where stuAddress='湖北武汉' or stuAddress='湖南长沙'; +-- 14.查询出笔试成绩不在70-90之间的信息,并按照笔试成绩升序排列 +select * from stuexam where writtenExam not BETWEEN 70 and 90 ORDER BY writtenExam asc; + +-- 15.查询年龄没有写的学生所有信息 +INSERT INTO `stuinfo` VALUES ('s2508', '上官婉儿', null, '湖北武汉', 8, 1); +select * from stuinfo; +select * from stuinfo where stuAge is null; +-- 16.查询年龄写了的学生所有信息 +select * from stuinfo where stuAge is not null; + +-- 17.查询姓张的学生信息 +select * FROM stuinfo where stuName like '张%'; + +-- 18.查询学生地址中有‘湖’字的信息 +select * FROM stuinfo where stuAddress like '%湖%'; + + +-- 19.查询姓张但名为一个字的学生信息 +-- +select * FROM stuinfo where stuName like '张_'; + +-- 20.查询姓名中第三个字为‘俊’的学生的信息,‘俊’后面有多少个字不限制 +-- +select * FROM stuinfo where stuName like '__俊%'; + +-- 21.按学生的年龄降序显示所有学生信息 +-- +select * from stuinfo order by stuAge desc; +-- 22.按学生的年龄降序和座位号升序来显示所有学生的信息 +-- +select * from stuinfo order by stuAge desc, stuSeat asc; + +-- 23显示笔试第一名的学生的考试号,学号,笔试成绩和机试成绩 +-- +select * from stuexam where writtenExam=(select max(writtenExam)from stuexam); +-- 24.显示机试倒数第一名的学生的考试号,学号,笔试成绩和机试成绩 +-- +select * from stuexam where labExam=(select MIN(labExam)from stuexam); + +-- 25.查询每个地方的学生的平均年龄 +-- +select stuAddress, AVG(stuAge) from stuinfo group by stuAddress; +-- 26.查询男女生的分别的年龄总和 +-- +select sum(stuAge) from stuinfo group by stuSex; +-- 27.查询每个地方的男女生的平均年龄和年龄的总和 +select avg(stuAge), sum(stuAge) from stuinfo group by stuSex; +``` + -- Gitee