当前位置:网站首页>Mysql database DQL exercise
Mysql database DQL exercise
2022-06-22 22:35:00 【Fire eye Dragon】
Table and data for exercise 1 :
CREATE TABLE student(
id INT,
name VARCHAR(20),
gender VARCHAR(20),
chinese INT,
english INT,
math INT
);
INSERT INTO student(id, name, gender, chinese, english, math) VALUES (1, ' Zhang Ming ', ' male ', 89, 78, 90);
INSERT INTO student(id, name, gender, chinese, english, math) VALUES (2, ' Li Jin ', ' male ', 67, 53, 95);
INSERT INTO student(id, name, gender, chinese, english, math) VALUES (3, ' Wang Wu ', ' Woman ', 87, 78, 77);
INSERT INTO student(id, name, gender, chinese, english, math) VALUES (4, ' Li Yi ', ' Woman ', 88, 98, 92);
INSERT INTO student(id, name, gender, chinese, english, math) VALUES (5, ' Li Cai ', ' male ', 82, 84, 67);
INSERT INTO student(id, name, gender, chinese, english, math) VALUES (6, ' Zhang Bao ', ' male ', 55, 85, 45);
INSERT INTO student(id, name, gender, chinese, english, math) VALUES (7, ' Huang Rong ', ' Woman ', 75, 65, 30);
INSERT INTO student(id, name, gender, chinese, english, math) VALUES (7, ' Huang Rong ', ' Woman ', 75, 65, 30);
Exercise one :
- Query the information of all students in the table
- Look up the names of all the students and their English scores
- Filter duplicate data in table
- Count the total score of each student
- Add... To the total score of all students 10 Points of specialty points of
- Use aliases to indicate student scores
- Query English score greater than 90 Classmate
- Total query score greater than 200 All students
- Query English scores in 80-90 Between the students
- Query English score is not in 80-90 Between the students
- Query math score is 89,90,91 Classmate
- Check the English scores of all students surnamed Li
- Query math score 80 And Chinese is divided into 80 Classmate
- Query English 80 Or total score 200 Classmate
- Output the math scores in descending order
- After sorting the total score, output , And then output it from high to low
- Sort and output the total scores of students surnamed Li
- How many boys and girls are there , And output the number of people in descending order
Answer 1 :
-- Query the information of all students in the table
SELECT * FROM student;
-- Look up the names of all the students and their English scores
SELECT name,english FROM student;
-- Filter duplicate data in table
SELECT DISTINCT * FROM student;
-- Count the total score of each student
SELECT name,chinese+english+math as total_score FROM student;
-- Add... To the total score of all students 10 Points of specialty points of
SELECT name,chinese+english+math+10 as total_score FROM student;
-- Use aliases to indicate student scores
SELECT name,chinese ' Chinese language and literature ',english ' English ',math ' mathematics ' FROM student;
-- Query English score greater than 90 Classmate
SELECT * FROM student WHERE english > 90;
-- Total query score greater than 200 All students
SELECT * FROM student WHERE (chinese+english+math) > 200;
SELECT name,chinese+english+math+10 as total_score FROM student WHERE (chinese+english+math) > 200;
-- Query English scores in 80-90 Between the students
SELECT * FROM student WHERE english >=80 AND english<90;
-- Query English score is not in 80-90 Between the students
SELECT * FROM student WHERE NOT (english >=80 AND english<90);
SELECT * FROM student WHERE english not BETWEEN 80 and 90;
SELECT * FROM student WHERE english>=80 and english<=90;
-- Query math score is 89,90,91 Classmate
SELECT * FROM student WHERE math=89 or math=90 or math = 91;
SELECT * FROM student WHERE math in (89,90,91);
-- Check the English scores of all students surnamed Li
SELECT * FROM student WHERE name LIKE ' Li %';
-- Query math score 80 And Chinese is divided into 80 Classmate
SELECT name,math,chinese FROM student WHERE math = 80 AND chinese=80;
-- Query English 80 Or total score 200 Classmate
SELECT * FROM student WHERE english = 80 and (chinese+math+english)=200;
-- Output the math scores in descending order
SELECT * FROM student ORDER BY math DESC;
-- After sorting the total score, output , And then output it from high to low
SELECT * FROM student ORDER BY (chinese+math+english) DESC;
-- Sort and output the total scores of students surnamed Li
SELECT * FROM student WHERE name like' Li %' ORDER BY (chinese+math+english) DESC;
-- How many boys and girls are there , And output the number of people in descending order
SELECT gender,COUNT(*) FROM student GROUP BY gender ORDER BY COUNT(*) DESC;
Tables and data for exercise 2 :
CREATE TABLE emp(
empno INT,
ename VARCHAR(50),
job VARCHAR(50),
mgr INT,
hiredate date,
sal INT,
comm INT,
deptno INT
);
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, '7987-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, 0, 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);
Exercise 2 :
- It is not listed in ascending order of employee number 10 Employee information of department No
- The second letter of the query name is not “A” And the salary is greater than 1000 Employee information for , In descending order of annual salary
- Average salary for each department
- Ask for the highest salary in each department
- Ask for the highest salary for each position in each department
- The average salary is greater than 2000 Department number of
- The average salary of the Department will be greater than 1500 The department number of the , Rank by department average salary in descending order
- Choose the name of the employee in the company who has the bonus , Wages
- Find out the difference between the maximum wage and the minimum wage
Answer two
-- It is not listed in ascending order of employee number 10 Employee information of department No
SELECT * FROM emp WHERE deptno !=10 ORDER BY empno ASC;
-- The second letter of the query name is not “A” And the salary is greater than 1000 Employee information for , In descending order of annual salary
SELECT * FROM emp WHERE ename NOT LIKE'_A%' AND sal >1000 ORDER BY (12*sal+IFNULL(comm,0)) DESC;
-- notes :ifnull(comm,0) If comm The value of is null, As 0, Otherwise, it's still the original value .
-- Average salary for each department
SELECT deptno,AVG(sal) FROM emp GROUP BY deptno;
-- Ask for the highest salary in each department
SELECT deptno,MAX(sal) FROM emp GROUP BY deptno;
-- Ask for the highest salary for each position in each department
SELECT deptno,job,MAX(sal) FROM emp GROUP BY deptno,job;
-- The average salary is greater than 2000 Department number of
SELECT deptno,AVG(sal) FROM emp GROUP BY deptno HAVING AVG(sal)>2000;
-- The average salary of the Department will be greater than 1500 The department number of the , Rank by department average salary in descending order
SELECT deptno,AVG(sal) FROM emp GROUP BY deptno HAVING AVG(sal)>1500 ORDER BY AVG(sal) DESC;
-- Choose the name of the employee in the company who has the bonus , Wages
SELECT * FROM emp WHERE comm is NOT NULL;
-- Find out the difference between the maximum wage and the minimum wage
SELECT MAX(sal)-MIN(sal) FROM emp;
边栏推荐
- liunx 安装mysql
- Implementation of depth traversal adjacency table in Figure 6-7
- 自助圖書館系統-Tkinter界面和openpyxl錶格綜合設計案例
- 【象棋人生】01 人生如棋
- Next permutation [give play to subjective initiative to discover laws]
- 【几何法视觉】4.2 分段线性变换
- Système de bibliothèque libre - service - cas de conception complète de l'interface tkinter et du formulaire openpyxl
- KDD'22 | 阿里: 基于EE探索的精排CTR预估
- Makefile:1860: recipe for target ‘cmake_ check_ build_ system‘ failed make: *** [cmake_check_build_syst
- 组合总数[标准回溯 + 回溯技巧--降低栈深度]
猜你喜欢

How to carry out encryption protection for equipment under extortion virus rampant

June 25 PMI certification examination site epidemic prevention requirements and examination room arrangement
![[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design](/img/5d/71c75a3622f7814f385d04b6148074.png)
[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design

Generate detailed API and parameters of QR code using qrcodejs2

Système de bibliothèque libre - service - cas de conception complète de l'interface tkinter et du formulaire openpyxl
A hundred lines of code to realize reliable delay queue based on redis

Reasons for the failure of digital transformation and the way to success
![[GWCTF 2019]mypassword XSS](/img/26/3611fd5aae21ea004dcfcc2c623328.png)
[GWCTF 2019]mypassword XSS

Why do you perform performance tests before the software goes online? How to find a software performance testing organization

SPA项目开发之动态树+数据表格+分页
随机推荐
AtCoder abc256全题解(区间合并模板、矩阵快速幂优化dp、线段树……)
Fundamentals of shell programming (Part 7: branch statement -if)
SPA项目开发之首页导航+左侧菜单
Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]
大不列颠泰迪熊加入PUBG 手游
Mask image modeling for self supervised representation pre training: CAE and its relationship with Mae and Beit
Delphi SOAP WebService 服务器端多个 SoapDataModule 要注意的问题
How to use the data dictionary function in the low code platform of the Internet of things?
The required reading for candidates | PMP the test on June 25 is approaching. What should we pay attention to?
Système de bibliothèque libre - service - cas de conception complète de l'interface tkinter et du formulaire openpyxl
Es total number of data queried by criteria
[mavros] mavros startup Guide
7-9 超级玛丽
NFT can only be viewed from afar, but not blatantly played
The mental process and understanding of visual project code design
二级造价工程师考前必备15个知识点来了!祝你旗开得胜!
VS代码一键整理快捷键
RealNetworks vs. Microsoft: the battle in the early streaming media industry
shell(34) : 時間
Rapideye, spot satellite remote sensing image data