当前位置:网站首页>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
边栏推荐
- How difficult is data governance and data innovation?
- A review of quantum neural networks 2022 for generating learning tasks
- 【LeetCode】15、三数之和
- Flutter 从零开始 007 输入框
- Flutter 从零开始 005 图片及Icon
- After the node is installed in the NVM, the display is not internal or external when the NPM instruction is used
- 1254. 统计封闭岛屿的数目
- Redis6 learning notes - Chapter 2 - Basic redis6 operations
- 海思3559万能平台搭建:获取数据帧修改后编码
- Global Capital Market 101:国内高净值人群最好的投资标的之一BREIT
猜你喜欢
After the node is installed in the NVM, the display is not internal or external when the NPM instruction is used
qt msvc 安装及调试
实现多方数据安全共享,解决普惠金融信息不对称难题
Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
Use of redis in projects
How do different types of variables compare with zero
Use of polarplot function in MATLAB
A Generic Deep-Learning-Based Approach for Automated Surface Inspection-论文阅读笔记
品达通用权限系统(Day 7~Day 8)
Four Misunderstandings of Internet Marketing
随机推荐
qt msvc 安装及调试
Generate entity classes from SQL Server database tables through EF core framework
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram and use scale_ x_ The log10 function configures the value range of the X axis to be logarithmic coordinates
The website with id 0 that was requested wasn‘t found. Verify the website and try again
ZABBIX monitors the number of TCP connections
R language ggplot2 visualization: gganimate package is based on Transition_ Time function to create dynamic scatter animation (GIF)
立创 EDA #学习笔记10# | 常用连接器元器件识别 和 无源蜂鸣器驱动电路
网络营销之四大误解
Redis6学习笔记-第二章-Redis6的基本操作
Go 语言入门很简单:Go 处理 XML 文件
The website with id 0 that was requested wasn‘t found. Verify the website and try again
90.(cesium篇)cesium高度监听事件
A high precision positioning approach for category support components with multiscale difference reading notes
Yolov5 export the pit encountered by onnx
海思3559 sample解析:venc
浏览器播放rtsp视频,基于nodeJs
Hannaiping of Qilin software: the construction of Digital China needs its own open source root community
VScode选中多个单词
Statistics on the number of closed Islands
Global capital market 101: Breit, one of the best investment targets for domestic high net worth people