From cb98dafd1b8c3463fcc4c9d32ab807b53bfeb3d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=BF=97=E9=B9=8F?= <326806914@qq.com> Date: Sat, 25 Feb 2023 13:01:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...03\344\271\240\344\275\234\344\270\232.md" | 60 ++++++++++++++++ ...03\344\271\240\344\275\234\344\270\232.md" | 71 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 "10 \346\234\261\345\277\227\351\271\217/5\343\200\201SELECT\350\257\255\345\217\245\345\237\272\347\241\200\347\273\203\344\271\240\344\275\234\344\270\232.md" create mode 100644 "10 \346\234\261\345\277\227\351\271\217/6\343\200\201\350\277\220\347\256\227\347\254\246\347\273\203\344\271\240\344\275\234\344\270\232.md" diff --git "a/10 \346\234\261\345\277\227\351\271\217/5\343\200\201SELECT\350\257\255\345\217\245\345\237\272\347\241\200\347\273\203\344\271\240\344\275\234\344\270\232.md" "b/10 \346\234\261\345\277\227\351\271\217/5\343\200\201SELECT\350\257\255\345\217\245\345\237\272\347\241\200\347\273\203\344\271\240\344\275\234\344\270\232.md" new file mode 100644 index 0000000..e845251 --- /dev/null +++ "b/10 \346\234\261\345\277\227\351\271\217/5\343\200\201SELECT\350\257\255\345\217\245\345\237\272\347\241\200\347\273\203\344\271\240\344\275\234\344\270\232.md" @@ -0,0 +1,60 @@ +```plsql +create database c charset utf8; +use c; +CREATE TABLE `user_profile` ( +`id` int , +`device_id` int, +`gender` varchar(14), +`age` int , +`university` varchar(32), +`gpa` float, +`active_days_within_30` float, +`question_cnt` float, +`answer_cnt` float +); +desc `user_profile`; +INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学',3.4,7,2,12); +INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学',4.0,15,5,25); +INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学',3.2,12,3,30); +INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学',3.6,5,1,2); +INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学',3.8,20,15,70); +INSERT INTO user_profile VALUES(6,2131,'male',28,'北京师范大学',3.3,15,7,13); +-- 题目:查询男性且GPA在3.5以上(不包括3.5)的用户的设备ID,性别、年龄、学校、gpa +select id,gender,age,university,gpa from `user_profile` where gpa > 3.5 +-- 题目:查询学校为北大或GPA在3.7以上(不包括3.7)的用户的设备ID,性别、年龄、学校、gpa +select id,gender,age,university,gpa from `user_profile` where university ='北京大学' or gpa > 3.7 +-- 题目:查询学校为北大、复旦和山大用户的设备ID,性别、年龄、学校、gpa +select id,gender,age,university,gpa from `user_profile`where university in('北京大学','复旦大学','山东大学') +-- 题目:查询gpa在3.5以上(不包括3.5)的山东大学用户 或 gpa在3.8以上(不包括3.8)的复旦大学同学 +select id,gender,age,university,gpa from `user_profile` where (gpa > 3.5 and university ='山东大学') or (gpa > 3.8 and university ='复旦大学') +-- 题目:所有大学中带有北京的用户信息 +select id,age,university from `user_profile` where university like '%北京%' +``` + +### 第一题 + +```sql +create database l charset utf8; +use l; +CREATE TABLE `user_profile` ( +`id` int, +`device_id` int, +`gender` varchar(14), +`age` int , +`university` varchar(32), +`province` varchar(32) +); +desc + +INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学','BeiJing'); +INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学','Shanghai'); +INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学','BeiJing'); +INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学','ZheJiang'); +INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学','Shandong'); +-- 题目:查询年龄20岁及以上且23岁及以下用户的设备ID、性别、年龄 +SELECT id, gender,age FROM `user_profile` where age >=20 and age <=30; +-- 题目:查询除复旦大学以外的所有用户的设备ID、性别、年龄、大学 +select id, gender,age,university FROM `user_profile` where university not in ('复旦大学') +-- 查询年龄不为空的用户的设备ID,性别,年龄,学校的信息 +select id, gender,age,university FROM `user_profile` where age is not null; +``` diff --git "a/10 \346\234\261\345\277\227\351\271\217/6\343\200\201\350\277\220\347\256\227\347\254\246\347\273\203\344\271\240\344\275\234\344\270\232.md" "b/10 \346\234\261\345\277\227\351\271\217/6\343\200\201\350\277\220\347\256\227\347\254\246\347\273\203\344\271\240\344\275\234\344\270\232.md" new file mode 100644 index 0000000..0180508 --- /dev/null +++ "b/10 \346\234\261\345\277\227\351\271\217/6\343\200\201\350\277\220\347\256\227\347\254\246\347\273\203\344\271\240\344\275\234\344\270\232.md" @@ -0,0 +1,71 @@ +```sql +create database z charset utf8; +use z; +CREATE TABLE( id INT, `name` VARCHAR(20), sex VARCHAR(20), tel VARCHAR(20), addr VARCHAR(50), salary FLOAT); +desc employee; +INSERT INTO employee(id,`name`,sex,tel,addr,salary)VALUES(10001,'张一一','男','13456789000','广东韶关',10010.58),(10002,'刘小红','女','13454319000','广东江门',12010.21),(10003,'李四','男','0751-1234567','广东佛山',10040.11),(10004,'刘小强','男','0755-5555555','广东深圳',15010.23),(10005,'王艳','男',NULL,'广东广州',14050.16); +-- **要求1:**查询出薪资在12000~13000之间的员工信息 +。select id,name,sex,tel,addr,salary from employee where salary >12000 and salary < 13000; +-- **要求2:**查询出姓“刘”的员工的工号,姓名,家庭住址。 +select yid,name,sex,tel,addr,salar from employee where name in ('刘') +-- **要求3:**将“李四”的家庭住址改为“广东韶关” +UPDATE employee set addr='广东韶关' WHERE `name`='李四'; +-- **要求4:**查询出名字中带“小”的员工 +select * from employee where name like '%小%'; +-- **要求5:**查询出薪资高于11000的男员工信息 +select id,name,sex,tel,addr,salary from employee where salary > 11000- +- **要求6:**查询没有登记电话号码的员工 +select id,name,sex,tel,addr,salary from employee where tel is null; +-- **要求7:**查询薪资高于12000或者家是广东深圳、广州的男员工 +select id,name,sex,tel,addr,salary from employee where salary >12000 or addr =( ('广东深圳'and '广东广州')and sex ='男'); +-- **要求8:**查询每个员工的年薪,显示“姓名、年薪” +select name,salary from employee; + + + + +create database adde charset utf8; +use adde; +CREATE TABLE `countries_info`( + `name` VARCHAR(100), + `continent` VARCHAR(100),CASE case_value + WHEN when_value THEN + statement_list + ELSE + statement_list +END CASE; + + `area` INT, + population INT, + gdp BIGINT +); +desc `countries_info`; +INSERT INTO countries_info VALUES +('Afghanistan','Asia',652230,25500100,20343000000), +('Albania','Europe',28748,2831741,12960000000), +('Algeria','Africa',2381741,37100000,188681000000), +('Andorra','Europe',468,78115,3712000000), +('Angola','Africa',1246700,20609294,100990000000); +-- 查询大国 的国家名称、人口和面积。 +-- +-- 如果一个国家满足下述两个条件之一,则认为该国是 大国 : +-- +-- * 面积至少为 300万平方公里(即,3000000 km2) +-- +-- * 人口至少为 2500 万(即 25000000) +select name,population,gdp from `countries_info` where gdp > 3000000 and population > 25000000 +查询属于亚洲的国家名称、所属大陆、面积、人口和 GDP 值 + select * from countries_info where continent = 'Asia'; +-- **要求3:**查询国土面积不足1万平方公里且人口不走10万人的国家信息 +select gdp from `countries_info` where gdp < 10000 and population < 100000 +-- **要求4:**查询国家名字中包含“o“字母的国家信息 +select name,continent from `countries_info` where continent like '%o%' +-- **要求5:**查询GDP值超过10000000000的国家信息 +select name ,continent,area,population,gdp from `countries_info` where gdp > 10000000000 +-- **要求6:**查询每个国家的人均贡献GDP值(GDP/人口总数)并显示为“国家名、人口、GDP值、人均贡献GDP值” +select name ,continent,area,population,gdp from `countries_info` where area; +-- *要求7:**查询人均贡献GDP值低于1000的国家信息。 +select name ,continent,area,population,gdp from `countries_info` where area < 1000 +-- **要求8:**查询每个国家的人均国土面积(面积/人口总数)并显示为“国家名、面积、人口、人均国土面积值” +select name,area,population,(area/countries_info.population) from countries_info; +``` -- Gitee