From 0802ca7cd92457dfb5f041ce93d5c1ce6634cd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=BA=86=E5=BC=BA?= Date: Wed, 22 Feb 2023 14:42:53 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2017?= =?UTF-8?q?=20=E8=91=A3=E5=BA=86=E5=BC=BA/202302022=E8=BF=90=E7=AE=97?= =?UTF-8?q?=E7=AC=A6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...22\350\277\220\347\256\227\347\254\246.md" | 89 ------------------- 1 file changed, 89 deletions(-) delete mode 100644 "17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" diff --git "a/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" "b/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" deleted file mode 100644 index 10dcfd8..0000000 --- "a/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" +++ /dev/null @@ -1,89 +0,0 @@ -# 笔记 - -```mysql -select 字段 as 命名 from 表名 #临时命名字段 - -select 字段1 运算符 字段2 as 命名 from 表名 #重新命名运算后的字段 - -select * from 表名 where 条件 #查询条件字段 - -select* from 表名 where 字段 like '%字符%' #搜素指定字符的字段 -``` - -# 作业 - -```mysql -create database class11 CHARSET utf8; -use class11; -CREATE TABLE employee( -id int, -`name` varchar(20), -sex varchar(20), -tel varchar(20), -addr varchar(50), -salary FLOAT -); -insert into employee values(10001,'张一一','男','13456789000','广东韶关',10010.58); -insert into employee values(10002,'刘小红','女','13454319000','广东江门',12010.21); -insert into employee VALUES(10003,'李四','男','0751-1234567','广东佛山',10040.11); -insert into employee VALUES(10004,'刘小强','男','0755-5555555','广东深圳',15010.23); -insert into employee VALUES(10005,'王艳','男',NULL,'广东广州',14050.16); -select * from employee; -#要求1:**查询出薪资在12000~13000之间的员工信息。 -select * from employee where salary >= 12000 and salary <=13000; -#**要求2:**查询出姓“刘”的员工的工号,姓名,家庭住址。 -select id,`name`,addr from employee WHERE `name` like '刘%'; -#**要求3:**将“李四”的家庭住址改为“广东韶关” -UPDATE employee set addr="广东昭关" where `name`='李四'; -#**要求4:**查询出名字中带“小”的员工 -select * from employee where `name` like '%小%'; -#**要求5:**查询出薪资高于11000的男员工信息 -select * from employee where salary>11000; -#**要求6:**查询没有登记电话号码的员工 -select * from employee where tel is null; -#**要求7:**查询薪资高于12000或者家是广东深圳、广州的男员工 -select * from employee where salary>12000 AND (addr='广东深圳' or addr= '广东广州') AND sex='男'; -#**要求8:**查询每个员工的年薪,显示“姓名、年薪” -select `name` '姓名',salary '年薪' from employee; - -``` - -```mysql -CREATE TABLE countries_info( - `name` VARCHAR(100), - `continent` VARCHAR(100), - `area` INT, - population INT, - gdp BIGINT -); -desc countries_info; -INSERT INTO countries_info VALUES('Afghanistan','Asia',652230,25500100,20343000000); -INSERT INTO countries_info VALUES('Albania','Europe',28748,2831741,12960000000); -INSERT INTO countries_info VALUES('Algeria','Africa',2381741,37100000,188681000000); -INSERT INTO countries_info VALUES('Andorra','Europe',468,78115,3712000000); -INSERT INTO countries_info VALUES('Angola','Africa',1246700,20609294,100990000000); -select * from countries_info; -#要求1:** 查询大国 的国家名称、人口和面积。 -select `name`,area,population from countries_info; -#如果一个国家满足下述两个条件之一,则认为该国是 大国 : -#- 面积至少为 300万平方公里(即,3000000 km2) -select * from countries_info where area>=3000000; -#- 人口至少为 2500 万(即 25000000) -select * from countries_info where population>=25000000; -#**要求2:**查询属于亚洲的国家名称、所属大陆、面积、人口和 GDP 值 -select * from countries_info where continent='Asia'; -#**要求3:**查询国土面积不足1万平方公里且人口不走10万人的国家信息 -select * from countries_info where area <10000 and population <100000; -#**要求4:**查询国家名字中包含“o“字母的国家信息 -select * from countries_info where `name`like '%o%'; -#**要求5:**查询GDP值超过10000000000的国家信息 -select * from countries_info where gdp>10000000000; -#**要求6:**查询每个国家的人均贡献GDP值(GDP/人口总数)并显示为“国家名、人口、GDP值、人均贡献GDP值” -select continent,population,gdp, gdp/population as '人均GDP' from countries_info; -#**要求7:**查询人均贡献GDP值低于1000的国家信息。 -select gdp/population as "人均GDP" from countries_info where (gdp/population)<1000; -#**要求8:**查询每个国家的人均国土面积(面积/人口总数)并显示为“国家名、面积、人口、人均国土面积值” - select continent,area,population,area/population as '人均国土面积' from countries_info; -``` - - -- Gitee From 3a34bdf466c600f53ec2b6e9d669807e3ffdb19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=BA=86=E5=BC=BA?= Date: Wed, 22 Feb 2023 22:48:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=BF=90=E7=AE=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...22\350\277\220\347\256\227\347\254\246.md" | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 "17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" diff --git "a/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" "b/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" new file mode 100644 index 0000000..10dcfd8 --- /dev/null +++ "b/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" @@ -0,0 +1,89 @@ +# 笔记 + +```mysql +select 字段 as 命名 from 表名 #临时命名字段 + +select 字段1 运算符 字段2 as 命名 from 表名 #重新命名运算后的字段 + +select * from 表名 where 条件 #查询条件字段 + +select* from 表名 where 字段 like '%字符%' #搜素指定字符的字段 +``` + +# 作业 + +```mysql +create database class11 CHARSET utf8; +use class11; +CREATE TABLE employee( +id int, +`name` varchar(20), +sex varchar(20), +tel varchar(20), +addr varchar(50), +salary FLOAT +); +insert into employee values(10001,'张一一','男','13456789000','广东韶关',10010.58); +insert into employee values(10002,'刘小红','女','13454319000','广东江门',12010.21); +insert into employee VALUES(10003,'李四','男','0751-1234567','广东佛山',10040.11); +insert into employee VALUES(10004,'刘小强','男','0755-5555555','广东深圳',15010.23); +insert into employee VALUES(10005,'王艳','男',NULL,'广东广州',14050.16); +select * from employee; +#要求1:**查询出薪资在12000~13000之间的员工信息。 +select * from employee where salary >= 12000 and salary <=13000; +#**要求2:**查询出姓“刘”的员工的工号,姓名,家庭住址。 +select id,`name`,addr from employee WHERE `name` like '刘%'; +#**要求3:**将“李四”的家庭住址改为“广东韶关” +UPDATE employee set addr="广东昭关" where `name`='李四'; +#**要求4:**查询出名字中带“小”的员工 +select * from employee where `name` like '%小%'; +#**要求5:**查询出薪资高于11000的男员工信息 +select * from employee where salary>11000; +#**要求6:**查询没有登记电话号码的员工 +select * from employee where tel is null; +#**要求7:**查询薪资高于12000或者家是广东深圳、广州的男员工 +select * from employee where salary>12000 AND (addr='广东深圳' or addr= '广东广州') AND sex='男'; +#**要求8:**查询每个员工的年薪,显示“姓名、年薪” +select `name` '姓名',salary '年薪' from employee; + +``` + +```mysql +CREATE TABLE countries_info( + `name` VARCHAR(100), + `continent` VARCHAR(100), + `area` INT, + population INT, + gdp BIGINT +); +desc countries_info; +INSERT INTO countries_info VALUES('Afghanistan','Asia',652230,25500100,20343000000); +INSERT INTO countries_info VALUES('Albania','Europe',28748,2831741,12960000000); +INSERT INTO countries_info VALUES('Algeria','Africa',2381741,37100000,188681000000); +INSERT INTO countries_info VALUES('Andorra','Europe',468,78115,3712000000); +INSERT INTO countries_info VALUES('Angola','Africa',1246700,20609294,100990000000); +select * from countries_info; +#要求1:** 查询大国 的国家名称、人口和面积。 +select `name`,area,population from countries_info; +#如果一个国家满足下述两个条件之一,则认为该国是 大国 : +#- 面积至少为 300万平方公里(即,3000000 km2) +select * from countries_info where area>=3000000; +#- 人口至少为 2500 万(即 25000000) +select * from countries_info where population>=25000000; +#**要求2:**查询属于亚洲的国家名称、所属大陆、面积、人口和 GDP 值 +select * from countries_info where continent='Asia'; +#**要求3:**查询国土面积不足1万平方公里且人口不走10万人的国家信息 +select * from countries_info where area <10000 and population <100000; +#**要求4:**查询国家名字中包含“o“字母的国家信息 +select * from countries_info where `name`like '%o%'; +#**要求5:**查询GDP值超过10000000000的国家信息 +select * from countries_info where gdp>10000000000; +#**要求6:**查询每个国家的人均贡献GDP值(GDP/人口总数)并显示为“国家名、人口、GDP值、人均贡献GDP值” +select continent,population,gdp, gdp/population as '人均GDP' from countries_info; +#**要求7:**查询人均贡献GDP值低于1000的国家信息。 +select gdp/population as "人均GDP" from countries_info where (gdp/population)<1000; +#**要求8:**查询每个国家的人均国土面积(面积/人口总数)并显示为“国家名、面积、人口、人均国土面积值” + select continent,area,population,area/population as '人均国土面积' from countries_info; +``` + + -- Gitee