当前位置:网站首页>MySQL composite query
MySQL composite query
2022-06-30 12:20:00 【Xiao Ni-_-】
List of articles
As we explained earlier mysql Table query is to query a table , In actual development, we often need to query multiple tables .
Basic query review
- Check that the salary is higher than 500 Or position is MANAGER Of employees , At the same time, their initials should be capitalized J

- Sort by department number in ascending order and employee's salary in descending order

- Use annual salary to sort in descending order

- Displays the name and position of the highest paid employee

- Displays information about employees whose wages are higher than the average

- Displays the average wage and maximum wage for each department

- It shows that the average wage is lower than 2000 Your department number and its average salary

- Displays the total number of employees for each position , Average wage

Multi-table query
In actual development, data often comes from different tables , Need multi table query .
Case a : Show employee name 、 The employee's salary and the name of the Department
Because the above data comes from EMP and DEPT surface , Therefore, joint query

In fact, we only need emp In the table deptno = dept In the table deptno Field records

Case 2 : The display department number is 10 The name of your department , Employee name and salary

Case three : Show the name of each employee , Wages , And salary level

Self join
Self join refers to joining queries in the same table
example :
Show employees FORD The number and name of the superior (mgr Is the employee leader's number –empno)
- Subquery used

- Use multi table query ( Self query )

Subquery
Subqueries are embedded in other sql Statement select sentence , Also called nested query
Single line sub query
A single row subquery is a subquery that returns one row of records
Example :
Show SMITH Employees in the same department

Multi line sub query
Multi row subquery is a subquery that returns multi row records
- in keyword
Query and 10 The name of the employee with the same position in department No , Position , Wages , Department number , But it doesn't include 10 Their own

- all keyword
Show salary ratio Department 30 The names of all the employees with high salaries 、 Salary and department number

- any keyword
Show salary ratio Department 30 Name of any employee with a higher salary 、 Salary and department number ( Including employees in their own department )

Multi column subquery
A single row subquery means that a subquery returns only a single column , Single line data ; Multi row sub query is to return single column and multi row data , It's all about single columns , Multi column subquery refers to the subquery statement that returns multiple column data
example : Query and SMITH All employees in the same department and position , Not included SMITH I am

stay from Clause using subqueries
Subquery statements appear in from clause . Here we need to use the technique of data query , Use a subquery as a temporary table .
Case study :
- Displays the name of each employee whose salary is higher than the average salary of his / her department 、 department 、 Wages 、 Average wage

- Find the name of the highest paid person in each department 、 Wages 、 department 、 Maximum wage

- Display information for each department ( Department name , Number , Address ) And the number of people
- Use multiple tables

- Use subquery

Merge query
in application , In order to merge multiple select The results of the implementation of , You can use the set operator union,union all
union
This operator is used to get the union of two result sets . When using this operator , Duplicate lines in the result set will be automatically removed .
Case study : Pay more than 2500 Or position is MANAGER Find out

union all
This operator is used to get the union of two result sets . When using this operator , Duplicate rows in the result set are not removed .
Case study : Pay more than 25000 Or position is MANAGER Find out

边栏推荐
- Parallel interface 8255A
- 通过EF Core框架根据SQL Server数据库表生成实体类
- 智慧法院新征程,无纸化办公,护航智慧法院绿色庭审
- 立创 EDA #学习笔记10# | 常用连接器元器件识别 和 无源蜂鸣器驱动电路
- List collection
- 并行接口8255A
- When building the second website with pagoda, the website always reports an error: no input file specified
- 1175. prime number arrangement: application of multiplication principle
- 用于生成学习任务的量子神经网络2022最新综述
- Use of redis in projects
猜你喜欢

AGCO AI frontier promotion (6.30)

Hisilicon 3559 universal platform construction: introduction to YUV format

How difficult is data governance and data innovation?

Conference Preview - Huawei 2012 lab global software technology summit - European session

Openmldb meetup No.4 meeting minutes

Talk about how to do hardware compatibility testing and quickly migrate to openeuler?

MySQL索引和优化的理解学习

Biological network analysis using deep learning

SuperMap iClient3D 11i for Cesium三维场景中图例使用说明
![Remove invalid parentheses [simulate stack with array]](/img/df/0a2ae5ae40adb833d52b2dddea291b.png)
Remove invalid parentheses [simulate stack with array]
随机推荐
用于生成学习任务的量子神经网络2022最新综述
SuperMap 3D SDKs_Unity插件开发——连接数据服务进行SQL查询
麒麟软件韩乃平:数字中国建设需要自己的开源根社区
Four Misunderstandings of Internet Marketing
1254. 统计封闭岛屿的数目
How difficult is data governance and data innovation?
Flutter 从零开始 007 输入框
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
Flutter 从零开始 006 单选开关和复选框
Global capital market 101: Breit, one of the best investment targets for domestic high net worth people
光谱共焦位移传感器的原理是什么?能应用那些领域?
并行接口8255A
3D视觉检测在生产流水的应用有哪些
海思3559萬能平臺搭建:獲取數據幀修改後編碼
Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
Vscode select multiple words
使用Power Designer工具构建数据库模型
lvgl 小部件样式篇
List集合
Iserver publishing es service query setting maximum return quantity