当前位置:网站首页>This section is used to supplement 3
This section is used to supplement 3
2022-07-26 18:41:00 【Piglet vs Hengge】
(1) Create database :mystudent
(2) establish 3 Data tables :
① Student list (stu)
② Employee list (emp)
③ Departmental table (dept)
The design is as follows. Complete the following information for the four tables :
Table structure :
# Student list :stu
mysql> desc stu;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| sid | char(6) | YES | | NULL | |
| sname | varchar(50) | YES | | NULL | |
| age | int | YES | | NULL | |
| gender | varchar(50) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
# Employee list :emp
mysql> desc emp;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| empno | int | YES | | NULL | |
| ename | varchar(50) | YES | | NULL | |
| job | varchar(50) | YES | | NULL | |
| mgr | int | YES | | NULL | |
| hiredate | date | YES | | NULL | |
| sal | decimal(7,2) | YES | | NULL | |
| comm | decimal(7,2) | YES | | NULL | |
| deptno | int | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
8 rows in set (0.00 sec)
# Departmental table :dept
mysql> desc dept;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| deptno | int | YES | | NULL | |
| dname | varchar(14) | YES | | NULL | |
| loc | varchar(13) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)Table data
mysql> # Student list
mysql> select * from stu;
+--------+----------+------+--------+
| sid | sname | age | gender |
+--------+----------+------+--------+
| S_1001 | liuYi | 35 | male |
| S_1002 | chenEr | 15 | female |
| S_1003 | zhangSan | 95 | male |
| S_1004 | liSi | 65 | female |
| S_1005 | wangWu | 55 | male |
| S_1006 | zhaoLiu | 75 | female |
| S_1007 | sunQi | 25 | male |
| S_1008 | zhouBa | 45 | female |
| S_1009 | wuJiu | 85 | male |
| S_1010 | zhengShi | 5 | female |
| S_1011 | xxx | NULL | NULL |
| S_1012 | NULL | 10 | female |
+--------+----------+------+--------+
12 rows in set (0.00 sec)
mysql> # Employee list
mysql> select * from emp;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 200.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-05-23 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
| 7988 | LISA | Procter & Gamble | 7782 | 2022-07-22 | 1200.00 | NULL | 50 |
+-------+--------+-----------+------+------------+---------+---------+--------+
15 rows in set (0.00 sec)
mysql> # Departmental table
mysql> select * from dept;
+--------+------------+----------+
| deptno | dname | loc |
+--------+------------+----------+
| 10 | ACCOUNTING | NEW YORK |
| 20 | RESEARCH | DALLAS |
| 30 | SALES | CHICAGO |
| 40 | OPERATIONS | BOSTON |
+--------+------------+----------+
4 rows in set (0.00 sec)Complete according to the above requirements MySQL Statement writing
# Create database myStudent
CREATE DATABASE IF NOT EXISTS `myStudent`;
# Create student table :stu
CREATE TABLE stu (
sid CHAR(6) COMMENT ' Student student id ',
sname VARCHAR(50) COMMENT ' The student's name ',
age INT COMMENT ' Student age ',
gender VARCHAR(50) COMMENT ' Student gender '
);
# Add data : Show the students stu Add data to
INSERT INTO stu VALUES('S_1001', 'liuYi', 35, 'male');
INSERT INTO stu VALUES('S_1002', 'chenEr', 15, 'female');
INSERT INTO stu VALUES('S_1003', 'zhangSan', 95, 'male');
INSERT INTO stu VALUES('S_1004', 'liSi', 65, 'female');
INSERT INTO stu VALUES('S_1005', 'wangWu', 55, 'male');
INSERT INTO stu VALUES('S_1006', 'zhaoLiu', 75, 'female');
INSERT INTO stu VALUES('S_1007', 'sunQi', 25, 'male');
INSERT INTO stu VALUES('S_1008', 'zhouBa', 45, 'female');
INSERT INTO stu VALUES('S_1009', 'wuJiu', 85, 'male');
INSERT INTO stu VALUES('S_1010', 'zhengShi', 5, 'female');
INSERT INTO stu VALUES('S_1011', 'xxx', NULL, NULL);
INSERT INTO stu VALUES('S_1012', NULL, 10, 'female');
# Create an employee table :emp
CREATE TABLE emp(
empno INT COMMENT ' Employee number ',
ename VARCHAR(50) COMMENT ' Employee name ',
job VARCHAR(50) COMMENT ' Staff work ',
mgr INT COMMENT ' Led number ',
hiredate DATE COMMENT ' Date of entry ',
sal DECIMAL(7,2) COMMENT ' a monthly salary ',
comm DECIMAL(7,2) COMMENT ' Bonus ',
deptno INT COMMENT ' Department number '
) ;
# Add data : Report to employees emp Add data to
INSERT INTO emp VALUES(7369,'SMITH','CLERK',7902,'1980-12-17',800,NULL,20);
INSERT INTO emp VALUES(7499,'ALLEN','SALESMAN',7698,'1981-02-20',1600,300,30);
INSERT INTO emp VALUES(7521,'WARD','SALESMAN',7698,'1981-02-22',1250,500,30);
INSERT INTO emp VALUES(7566,'JONES','MANAGER',7839,'1981-04-02',2975,NULL,20);
INSERT INTO emp VALUES(7654,'MARTIN','SALESMAN',7698,'1981-09-28',1250,1400,30);
INSERT INTO emp VALUES(7698,'BLAKE','MANAGER',7839,'1981-05-01',2850,NULL,30);
INSERT INTO emp VALUES(7782,'CLARK','MANAGER',7839,'1981-06-09',2450,NULL,10);
INSERT INTO emp VALUES(7788,'SCOTT','ANALYST',7566,'1987-04-19',3000,NULL,20);
INSERT INTO emp VALUES(7839,'KING','PRESIDENT',NULL,'1981-11-17',5000,NULL,10);
INSERT INTO emp VALUES(7844,'TURNER','SALESMAN',7698,'1981-09-08',1500,200,30);
INSERT INTO emp VALUES(7876,'ADAMS','CLERK',7788,'1987-05-23',1100,NULL,20);
INSERT INTO emp VALUES(7900,'JAMES','CLERK',7698,'1981-12-03',950,NULL,30);
INSERT INTO emp VALUES(7902,'FORD','ANALYST',7566,'1981-12-03',3000,NULL,20);
INSERT INTO emp VALUES(7934,'MILLER','CLERK',7782,'1982-01-23',1300,NULL,10);
# Create department table :dept
CREATE TABLE dept(
deptno INT COMMENT ' Department number ',
dname VARCHAR(14) COMMENT ' Department name ',
loc VARCHAR(13) COMMENT ' Department Address '
);
INSERT INTO dept VALUES(10, 'ACCOUNTING', 'NEW YORK');
INSERT INTO dept VALUES(20, 'RESEARCH', 'DALLAS');
INSERT INTO dept VALUES(30, 'SALES', 'CHICAGO');
INSERT INTO dept VALUES(40, 'OPERATIONS', 'BOSTON');
Query statement writing order :select – from- where- group by- having- order by-limit
Query statement execution order :from - where -group by - having - select - order by-limit
Single table query :
01、 Basic query
1. Inquire about stu All fields in the table
2. Query the specified column in the student table
02、 Conditions of the query
3. Check gender for female , And older than 50 The record of
4. Check gender for female , And older than 50 Employee number and name
5. The student ID is S_1001, Or the name is lisi The record of
6. The student ID is S_1001,S_1002,S_1003 The record of
7. It's not S_1001,S_1002,S_1003 The record of
8. Query age is null The record of
9. The age of inquiry is 20 To 40 Between student records
10. Check the student records of non male students
11. The search name is not null Student records of
03、 Fuzzy query
12. Search name by 5 Student records in letters
13. Search name by 5 Letter composition , And No 5 The letters are "i" Student records of
14. Check the name with “z” The student record at the beginning
15. Check the number of 2 The letters are “i” Student records of
16. The query name contains “a” The student record of letters
04、 Field control query
17. Remove duplicate records DISTINCT
18. Check the sum of the employee's monthly salary and Commission Be careful : A number with NULL Carry out operations , The result is NULL
19. Add an alias to the column name , Use As keyword As Keywords can be omitted
05、 Sort
20. Check all student records , Sort by age in ascending order
21. Check all student records , Sort by age in descending order
22. Check all employees , Sort by monthly salary in descending order , If the monthly salary is the same , Sort by number in ascending order
23. Check all employees , Sort by monthly salary in descending order , If the monthly salary is the same , Sort by number in descending order
24. Check that the salary is higher than 1600 Employee records of , And sort in descending order according to salary
06、 Aggregate functions
25.COUNT(): The specified column of statistics is not NULL The number of record lines
26.MAX(): Calculate the maximum value of the specified column , If the specified column is of string type , So use string sort operation
27.MIN(): Calculate the minimum value of the specified column , If the specified column is of string type , So use string sort operation
28.SUM(): Calculates the value of the specified column and , If the specified column type is not a numeric type , So the result is 0
29.AVG(): Calculate the average value of the specified column , If the specified column type is not a numeric type , So the result is 0
30. Inquire about emp The monthly salary in the table is more than 2500 The number of people
31. The sum of monthly salary and commission is greater than 2500 The number of yuan
32. Check the monthly salary of all employees + Commission and
07、 Group query
33. Query the department number of each department and the salary and
34. Check the department number of each department and the number of people in each department
35. Query the department number of each department and the salary of each department is greater than 1500 The number of people
08、having Clause
36. The total salary is greater than 9000 Department number and salary and
09、limit
37. Inquire about 5 rows , Start with 0 Start
38. Inquire about 10 rows , Start with 3 Start
Multi-table query
01、 Merge result set
02、 Link query
边栏推荐
- OpenGL中的视差贴图的着色器代码
- Continue to work hard on your skills, and the more you learn, the more you will learn
- 自动化测试工具-Playwright(快速上手)
- Concentrate, heart to heart! The Chinese funded mobile phone Enterprises Association (CMA) of India is officially operational!
- Duplicate gallerycms character length limit short domain name bypass
- The second set of 2020 American Asian individual match
- 开发winform中遇到的一些问题汇总(持续跟新)
- 隐私计算基础组件系列-混淆电路
- 分布式链路追踪Jaeger在Golang中的使用
- 还在用Xshell?推荐这个更现代的终端连接工具
猜你喜欢

Meta Cambria handle exposure, active tracking + multi tactile feedback scheme

云服务器mySQL提示报错

Oracle day 2 (Views, indexes, PLSQL, cursors, stored procedures and stored functions, triggers, JDBC access stored procedures and stored functions)

Hello World

Day 4 of SSM practice_ Get user name_ User exit_ User CRUD_ Password encryption_ Roles_ jurisdiction

During the oppo interview, 16 questions were thrown over. I was stupid

ssm练习第二天_项目拆分moudle_基本增删改查_批量删除_一对一级联查询

flex布局

Data warehouse: fact table of detailed dimensional modeling

Oracle第一天(开发常用的知识点再回顾整理下)
随机推荐
Sudden! Arm stops cooperating with Huawei! How big is the impact on Huawei?
J9数字论:如何避免踩雷多头陷阱?
Ten year structure five year life-06 impulse to leave
Greedy - 455. Distribute cookies
链表-两个链表的第一个公共结点
Offer set (1)
Module 8 job message data MySQL table design
Lombok常用注解
Hello World
还在用Xshell?推荐这个更现代的终端连接工具
数据安全知识体系
复现gallerycms字符长度限制短域名绕过
Oracle第一天(开发常用的知识点再回顾整理下)
Maximum sum of continuous subarray of sword finger offer (2)
What should we do after the PMP Exam is postponed on July 30?
Mpc5744p burning to 98% can not continue to download the program
Test cases of common functions
J9 number theory: how to avoid the trap of stepping on thunder?
如何组装一个注册中心
File upload and download test point