diff --git "a/52\347\250\213\345\270\205\347\277\224/DQL\344\275\234\344\270\232.md" "b/52\347\250\213\345\270\205\347\277\224/DQL\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..46348f1d4f5002d18c08ad2bd7613b9b9032d269 --- /dev/null +++ "b/52\347\250\213\345\270\205\347\277\224/DQL\344\275\234\344\270\232.md" @@ -0,0 +1,108 @@ +| ```mysql | | | +| -------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | [2](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_2) | ## 第1题:员工表 | +| | [3](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_3) | | +| | [4](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_4) | mysql | +| | [5](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_5) | drop table if exists `employee`; | +| | [6](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_6) | create database test charset utf8; | +| | [7](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_7) | #创建employee表 | +| | [8](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_8) | use test; | +| | [9](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_9) | CREATE TABLE employee( | +| | [10](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_10) | id INT, | +| | [11](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_11) | `name` VARCHAR(20), | +| | [12](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_12) | sex VARCHAR(20), | +| | [13](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_13) | tel VARCHAR(20), | +| | [14](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_14) | addr VARCHAR(50), | +| | [15](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_15) | salary FLOAT | +| | [16](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_16) | ); | +| | [17](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_17) | | +| | [18](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_18) | #添加信息 | +| | [19](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_19) | INSERT INTO employee(id,`name`,sex,tel,addr,salary)VALUES | +| | [20](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_20) | (10001,'张一一','男','13456789000','广东韶关',10010.58), | +| | [21](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_21) | (10002,'刘小红','女','13454319000','广东江门',12010.21), | +| | [22](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_22) | (10003,'李四','男','0751-1234567','广东佛山',10040.11), | +| | [23](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_23) | (10004,'刘小强','男','0755-5555555','广东深圳',15010.23), | +| | [24](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_24) | (10005,'王艳','男',NULL,'广东广州',14050.16); | +| | [25](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_25) | | +| | [26](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_26) | \| **id** \| **name** \| **sex** \| **tel** \| **addr** \| **salary** \| | +| | [27](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_27) | \| ------ \| -------- \| ------- \| ------------ \| -------- \| ---------- \| | +| | [28](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_28) | \| 10001 \| 张一一 \| 男 \| 13456789000 \| 广东韶关 \| 10010.58 \| | +| | [29](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_29) | \| 10002 \| 刘小红 \| 女 \| 13454319000 \| 广东江门 \| 12010.21 \| | +| | [30](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_30) | \| 10003 \| 李四 \| 男 \| 0751-1234567 \| 广东佛山 \| 10040.11 \| | +| | [31](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_31) | \| 10004 \| 刘小强 \| 男 \| 0755-5555555 \| 广东深圳 \| 15010.23 \| | +| | [32](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_32) | \| 10005 \| 王艳 \| 女 \| NULL \| 广东广州 \| 14050.16 \| | +| | [33](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_33) | select * from employee; | +| | [34](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_34) | **要求1:**查询出薪资在12000~13000之间的员工信息。 | +| | [35](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_35) | select * from employee where salary between 12000 and 13000; | +| | [36](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_36) | **要求2:**查询出姓“刘”的员工的工号,姓名,家庭住址。 | +| | [37](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_37) | select id,name,addr from employee where name like'刘%'; | +| | [38](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_38) | **要求3:**将“李四”的家庭住址改为“广东韶关” | +| | [39](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_39) | update employee set addr = '广东韶关' where name = '李四'; | +| | [40](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_40) | **要求4:**查询出名字中带“小”的员工 | +| | [41](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_41) | select * from employee where name like '%小%'; | +| | [42](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_42) | **要求5:**查询出薪资高于11000的男员工信息 | +| | [43](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_43) | select * from employee where salary > 11000 and sex ='男'; | +| | [44](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_44) | **要求6:**查询没有登记电话号码的员工 | +| | [45](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_45) | select * from employee where tel is null; | +| | [46](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_46) | **要求7:**查询薪资高于12000或者家是广东深圳、广州的男员工 | +| | [47](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_47) | select * from employee where sex ='男' and (salary > 12000 )or(addr in('广东深圳','广东广州')) ; | +| | [48](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_48) | **要求8:**查询每个员工的年薪,显示“姓名、年薪” | +| | [49](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_49) | select name '姓名',salary '底薪', salary * 12 '年薪' from employee; | +| | [50](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_50) | | +| | [51](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_51) | ## 第2题:国家信息表 | +| | [52](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_52) | | +| | [53](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_53) | countries_info表中存储了国家名称、所属大陆、面积、人口和 GDP 值。 | +| | [54](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_54) | create database test2 charset utf8; | +| | [55](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_55) | use test2; | +| | [56](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_56) | DROP TABLE IF EXISTS `countries_info`; | +| | [57](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_57) | CREATE TABLE `countries_info`( | +| | [58](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_58) | `name` VARCHAR(100), | +| | [59](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_59) | `continent` VARCHAR(100), | +| | [60](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_60) | `area` INT, | +| | [61](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_61) | population INT, | +| | [62](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_62) | gdp BIGINT | +| | [63](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_63) | ); | +| | [64](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_64) | | +| | [65](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_65) | INSERT INTO countries_info VALUES | +| | [66](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_66) | ('Afghanistan','Asia',652230,25500100,20343000000), | +| | [67](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_67) | ('Albania','Europe',28748,2831741,12960000000), | +| | [68](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_68) | ('Algeria','Africa',2381741,37100000,188681000000), | +| | [69](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_69) | ('Andorra','Europe',468,78115,3712000000), | +| | [70](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_70) | ('Angola','Africa',1246700,20609294,100990000000); | +| | [71](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_71) | ``` | +| | [72](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_72) | 表数据样例: | +| | [73](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_73) | | +| | [74](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_74) | ```mysql | +| | [75](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_75) | +-------------+-----------+---------+------------+--------------+ | +| | [76](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_76) | \| name \| continent \| area \| population \| gdp \| | +| | [77](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_77) | +-------------+-----------+---------+------------+--------------+ | +| | [78](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_78) | \| Afghanistan \| Asia \| 652230 \| 25500100 \| 20343000000 \| | +| | [79](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_79) | \| Albania \| Europe \| 28748 \| 2831741 \| 12960000000 \| | +| | [80](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_80) | \| Algeria \| Africa \| 2381741 \| 37100000 \| 188681000000 \| | +| | [81](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_81) | \| Andorra \| Europe \| 468 \| 78115 \| 3712000000 \| | +| | [82](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_82) | \| Angola \| Africa \| 1246700 \| 20609294 \| 100990000000 \| | +| | [83](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_83) | +-------------+-----------+---------+------------+--------------+ | +| | [84](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_84) | select * from countries_info | +| | [85](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_85) | | +| | [86](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_86) | **要求1:** 查询大国 的国家名称、人口和面积。 | +| | [87](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_87) | | +| | [88](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_88) | 如果一个国家满足下述两个条件之一,则认为该国是 大国 : | +| | [89](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_89) | | +| | [90](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_90) | - 面积至少为 300万平方公里(即,3000000 km2) | +| | [91](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_91) | | +| | [92](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_92) | - 人口至少为 2500 万(即 25000000) | +| | [93](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_93) | select name,population,area from countries_info where area > 3000000 or population > 25000000; | +| | [94](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_94) | **要求2:**查询属于亚洲的国家名称、所属大陆、面积、人口和 GDP 值 | +| | [95](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_95) | select * from countries_info where continent = 'Asia' ; | +| | [96](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_96) | **要求3:**查询国土面积不足1万平方公里且人口不走10万人的国家信息 | +| | [97](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_97) | select * from countries_info where area < 10000 and population < 100000; | +| | [98](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_98) | **要求4:**查询国家名字中包含“o“字母的国家信息 | +| | [99](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_99) | select * from countries_info where name like '%o%'; | +| | [100](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_100) | **要求5:**查询GDP值超过10000000000的国家信息 | +| | [101](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_101) | select * from countries_info where gdp > 10000000000; | +| | [102](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_102) | **要求6:**查询每个国家的人均贡献GDP值(GDP/人口总数)并显示为“国家名、人口、GDP值、人均贡献GDP值” | +| | [103](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_103) | select name '国家名', population '人口', gdp 'GDP值',gdp/ population '人均贡献GDP值' from countries_info; | +| | [104](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_104) | **要求7:**查询人均贡献GDP值低于1000的国家信息。 | +| | [105](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_105) | select * from countries_info where gdp / population < 1000; | +| | [106](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_106) | **要求8:**查询每个国家的人均国土面积(面积/人口总数)并显示为“国家名、面积、人口、人均国土面积值” | +| | [107](https://gitee.com/fang-zengxing/mysql-base/commit/79daf0a776910f6cdc1c09a5fdb7a40e1b7b6244#ab8c8689102a3c159b3c030567c88aadfed7d90d_0_107) | select name '国家名',area '面积', population '人口',area/ population '人均国土面积值' from countries_info; | \ No newline at end of file diff --git "a/52\347\250\213\345\270\205\347\277\224/\344\275\234\344\270\2322.md" "b/52\347\250\213\345\270\205\347\277\224/\344\275\234\344\270\2322.md" new file mode 100644 index 0000000000000000000000000000000000000000..49d5e2fec0154bf0dd1d0fa40b14a1e37e621d55 --- /dev/null +++ "b/52\347\250\213\345\270\205\347\277\224/\344\275\234\344\270\2322.md" @@ -0,0 +1,347 @@ +# 作业 +## 第一题 +-- 1、创建数据库test01_company +CREATE database test01_company +use test01_company; +-- 2、创建表格offices +create table offices( +officeCode int, +city varchar(30), +address varchar(50), +country varchar(50), +postalCode VARCHAR(25) + +); + +| -- | 字段名 | 数据类型 | +| ------------------------------------------------------------ | ---------- | ------------- | +| -- | officeCode | int | +| -- | city | varchar(30) | +| -- | address | varchar(50) | +| -- | country | varchar(50) | +| -- | postalCode | varchar(25) | +| -- | | | +| -- 3、创建表格employees | | | +| create table employees( | | | +| empNum int(11), | | | +| lastName VARCHAR(50), | | | +| firstName VARCHAR(50), | | | +| mobile VARCHAR(25), | | | +| `code` int, | | | +| jobTitle VARCHAR(50), | | | +| birth date, | | | +| Note VARCHAR(255), | | | +| Sex VARCHAR(5) | | | +| ); | | | +| -- | | | +| -- | 字段名 | 数据类型 | +| -- | --------- | ------------- | +| -- | empNum | int(11) | +| -- | lastName | varchar(50) | +| -- | firstName | varchar(50) | +| -- | mobile | varchar(25) | +| -- | code | int | +| -- | jobTitle | varchar(50) | +| -- | birth | date | +| -- | Note | varchar(255) | +| -- | Sex | varchar(5) | +| -- | | | +| -- **要求4:**将表employees的mobile字段修改到code字段后面。 | | | +| alter table employees modify mobile VARCHAR(25) after code; | | | +| -- | | | +| -- **要求5:**将表employees的birth字段改名为birthday; | | | +| alter table employees change birth birthday date; | | | +| -- | | | +| -- **要求6:**修改sex字段,数据类型为char(1)。 | | | +| alter table employees modify sex char(1); | | | +| -- | | | +| -- **要求7:**删除字段note; | | | +| alter table employees drop note; | | | +| -- | | | +| -- **要求8:**增加字段名favoriate_activity,数据类型为varchar(100); | | | +| alter table employees add favoriate_activity VARCHAR(100); | | | +| -- | | | +| -- **要求9:**将表employees的名称修改为 employees_info | | | +| alter table employees rename to employees_info; | | | +| -- | | | +| -- ```mysql | | | +| -- | | | +| -- ``` | | | +| -- | | | +| -- | | | +| -- | | | + +## 第二题 + + + +-- 1、创建数据库test02db +create database test02db; + +use test02db; + +-- 2、创建表格pet +drop table pet; +create table pet( +`name` VARCHAR(20), +`owner` VARCHAR(20), + species VARCHAR(20), + sex char(1), + birth year, + death year + +); + +| -- | 字段名 | 字段说明 | 数据类型 | +| ------------------------------------------------------- | ------- | -------- | ----------- | +| -- | name | 宠物名称 | varchar(20) | +| -- | owner | 宠物主人 | varchar(20) | +| -- | species | 种类 | varchar(20) | +| -- | sex | 性别 | char(1) | +| -- | birth | 出生日期 | year | +| -- | death | 死亡日期 | year | +| -- | | | | +| -- 3、添加记录 | | | | +| insert into pet values | | | | +| ('Fluffy','harold','Cat','f',2003,2010), | | | | +| ('Claws','gwen','Cat','m',2004,null), | | | | +| ('Buffy',null,'Dog','f',2009,null), | | | | +| ('Fang','benny','Dog','m',2000,null), | | | | +| ('bowser','diane','Dog','m',2003,2009), | | | | +| ('Chirpy',null,'Bird','f',2008,null); | | | | +| -- | | | | +| -- | name | owner | species | +| -- | ------ | ------ | ------- | +| -- | Fluffy | harold | Cat | +| -- | Claws | gwen | Cat | +| -- | Buffy | | Dog | +| -- | Fang | benny | Dog | +| -- | bowser | diane | Dog | +| -- | Chirpy | | Bird | +| -- | | | | +| -- 4、 添加字段主人的生日owner_birth。 | | | | +| alter table pet add owner_birth int; | | | | +| -- | | | | +| -- 5、 将名称为Claws的猫的主人改为kevin | | | | +| update pet set `owner`='kevin' where name='Claws'; | | | | +| -- | | | | +| -- 6、 将没有死的狗的主人改为duck | | | | +| update pet set `owner`='duck' where death is null; | | | | +| -- | | | | +| -- 7、 查询没有主人的宠物的名字; | | | | +| select `owner` pet WHERE `owner` is null; | | | | +| -- | | | | +| -- 8、 查询已经死了的cat的姓名,主人,以及去世时间; | | | | +| select name,`owner`,death from pet WHERE species='Cat'; | | | | +| -- | | | | +| -- 9、 删除已经死亡的狗 | | | | +| delete from pet where species='Dog' and death='2009'; | | | | +| -- | | | | +| -- 10、查询所有宠物信息 | | | | +| select * from pet; | | | | +| -- | | | | +| -- ```sql | | | | +| -- | | | | +| -- ``` | | | | +| -- | | | | +| -- ## 第3题 | | | | +| -- | | | | + +## 第三题 + +-- 1、创建数据库:test03_company +create database test03_company; + +use test03_company; + +-- ```sql +-- create database test03_company charset utf8; + +-- ``` + +-- 2、在此数据库下创建如下3表,数据类型,宽度,是否为空根据实际情况自己定义。 + +-- A. 部门表(department):部门编号(depid),部门名称(depname),部门简介(deinfo);其中部门编号为主键。 + +-- ```mysql +-- use test03_company ; +create table department( +depid int primary key auto_increment, +depname char(10) not null unique key, +deinfo varchar(200) +); + +-- ``` + +-- B. 雇员表(employee):雇员编号(empid),姓名(name),性别(sex),职称(title),出生日期(birthday),所在部门编号(depid);其中 + +-- * 雇员编号为主键; +-- * 部门编号为外键,外键约束等级为(on update cascade 和on delete set null); + +-- * 性别默认为男; + +-- ```mysql +ALTER DATABASE test03_company CHARACTER SET utf8; +create table employee ( +empid int primary key auto_increment, +`name` varchar(10) not null, +sex enum('男','女') not null default'男', +title varchar(10), +birthday date, +depid int, +foreign key(depid) references department(depid) + +); + +-- + +-- C. 工资表(salary):雇员编号(empid),基本工资(basesalary),职务工资(titlesalary),扣除(deduction)。其中雇员编号为主键。 + +-- 3、给工资表(salary)的雇员编号(empid)增加外键约束,外键约束等级为(on update cascade 和on delete cascade) +create table salary( +empid int primary key, +basesalary double, +titlesalary double, +deduction double, +foreign key(empid) references employee(empid) + +); + +-- 4、添加数据如下: + +-- 部门表: +desc department; +show create table department; +alter table department convert to character set utf8; +insert into department values +(111,'生产部',null), +(222,'销售部',null), + +(333,'人事部','人力资源管理'); + +| -- | 部门编号 | 部门名称 | 部门简介 | +| ----------------------------------------------- | -------- | -------- | ------------ | +| -- | 111 | 生产部 | Null | +| -- | 222 | 销售部 | Null | +| -- | 333 | 人事部 | 人力资源管理 | +| -- | | | | +| -- 雇员表: | | | | +| insert into employee values | | | | +| (1001,'张三','男','高级工程师','1975-1-1',111), | | | | +| (1002,'李四','女','助师','1985-1-1',111), | | | | +| (1003,'王五','男','工程师','1978-11-11',222), | | | | +| (1004,'张六','男','工程师','1999-1-1',222); | | | | +| -- | | | | +| -- | 雇员编号 | 姓名 | 性别 | +| -- | -------- | ---- | ---- | +| -- | 1001 | 张三 | 男 | +| -- | 1002 | 李四 | 女 | +| -- | 1003 | 王五 | 男 | +| -- | 1004 | 张六 | 男 | +| -- | | | | +| -- 工资表: | | | | +| insert into salary values | | | | +| (1001,2200,1100,200), | | | | +| (1002,1200,200,null), | | | | +| (1003,2900,700,200), | | | | +| (1004,1950,700,150); | | | | +| -- | | | | +| -- | 雇员编号 | 基本工资 | 职务工资 | +| -- | -------- | -------- | -------- | +| -- | 1001 | 2200 | 1100 | +| -- | 1002 | 1200 | 200 | +| -- | 1003 | 2900 | 700 | +| -- | 1004 | 1950 | 700 | +| -- | | | | +| -- | | | | +| -- | | | | + +## 第四题 + + + +-- 1、创建一个数据库:test04_school +create database test04_school; + +use test04_school; + +-- 2、创建如下表格 +create table Department( +DepNo int(10) primary key not null unique, +DepName varchar(20) not null, +DepNote varchar(50) + +); + +-- 表1 Department表的定义 + +| -- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +| --------------------------------------------------------- | ---------- | ------------ | ------------------ | ---------- | --------- | ---------- | ------------ | +| -- | DepNo | 部门号 | int(10) | 是 | 否 | 是 | 是 | +| -- | DepName | 部门名称 | varchar(20) | 否 | 否 | 是 | 否 | +| -- | DepNote | 部门备注 | Varchar(50) | 否 | 否 | 否 | 否 | +| -- | | | | | | | | +| -- 表2 Teacher表的定义 | | | | | | | | +| create table Teacher( | | | | | | | | +| Number int primary key not null unique, | | | | | | | | +| `Name` varchar(30) not null, | | | | | | | | +| Sex VARCHAR(4), | | | | | | | | +| Birth date, | | | | | | | | +| DepNo int, | | | | | | | | +| Salary float, | | | | | | | | +| Address VARCHAR(100), | | | | | | | | +| foreign key(DepNo) references Department(DepNo) | | | | | | | | +| ); | | | | | | | | +| -- | | | | | | | | +| -- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +| -- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +| -- | Number | 教工号 | int | 是 | 否 | 是 | 是 | +| -- | Name | 姓名 | varchar(30) | 否 | 否 | 是 | 否 | +| -- | Sex | 性别 | varchar(4) | 否 | 否 | 否 | 否 | +| -- | Birth | 出生日期 | date | 否 | 否 | 否 | 否 | +| -- | DepNo | 部门号 | int | 否 | 是 | 否 | 否 | +| -- | Salary | 工资 | float | 否 | 否 | 否 | 否 | +| -- | Address | 家庭住址 | varchar(100) | 否 | 否 | 否 | 否 | +| -- | | | | | | | | +| -- 3、添加记录 | | | | | | | | +| alter table Department convert to character set utf8; | | | | | | | | +| insert into Department VALUES | | | | | | | | +| (601,'软件技术系','软件技术等专业'), | | | | | | | | +| (602,'网络技术系','多媒体技术等专业'), | | | | | | | | +| (603,'艺术设计系','广告艺术设计等专业'), | | | | | | | | +| (604,'管理工程系','连锁经营管理等专业'); | | | | | | | | +| -- | | | | | | | | +| -- | **DepNo** | **DepName** | **DepNote** | | | | | +| -- | --------- | ----------- | ------------------ | | | | | +| -- | 601 | 软件技术系 | 软件技术等专业 | | | | | +| -- | 602 | 网络技术系 | 多媒体技术等专业 | | | | | +| -- | 603 | 艺术设计系 | 广告艺术设计等专业 | | | | | +| -- | 604 | 管理工程系 | 连锁经营管理等专业 | | | | | +| alter table Teacher convert to character set utf8; | | | | | | | | +| insert into Teacher VALUES | | | | | | | | +| (2001,'Tom','女','1970-01-10',602,4500,'四川省绵阳市'), | | | | | | | | +| (2002,'Lucy','男','1983-12-18',601,2500,'北京市昌平区'), | | | | | | | | +| (2003,'Mike','男','1990-06-01',604,1500,'重庆市渝中区'), | | | | | | | | +| (2004,'James','女','1980-10-20',602,3500,'四川省成都市'), | | | | | | | | +| (2005,'Jack','男','1975-05-30',603,1200,'重庆市南岸区'); | | | | | | | | +| -- | | | | | | | | +| -- | **Number** | **Name** | **Sex** | **Birth** | **DepNo** | **Salary** | **Address** | +| -- | ---------- | -------- | ------- | ---------- | --------- | ---------- | ------------ | +| -- | 2001 | Tom | 女 | 1970-01-10 | 602 | 4500 | 四川省绵阳市 | +| -- | 2002 | Lucy | 男 | 1983-12-18 | 601 | 2500 | 北京市昌平区 | +| -- | 2003 | Mike | 男 | 1990-06-01 | 604 | 1500 | 重庆市渝中区 | +| -- | 2004 | James | 女 | 1980-10-20 | 602 | 3500 | 四川省成都市 | +| -- | 2005 | Jack | 男 | 1975-05-30 | 603 | 1200 | 重庆市南岸区 | +| -- | | | | | | | | +| -- 4、用SELECT语句查询Teacher表的所有记录。 | | | | | | | | +| select * from Teacher; | | | | | | | | +| -- | | | | | | | | +| -- ```mysql | | | | | | | | +| -- | | | | | | | | +| -- ``` | | | | | | | | +| -- | | | | | | | | +| -- | | | | | | | | +| -- | | | | | | | | +| -- | | | | | | | | +| -- | | | | | | | | +| -- | | | | | | | | \ No newline at end of file