当前位置:网站首页>MySQL learning notes
MySQL learning notes
2022-04-22 07:18:00 【Xiaofan Hall】

-- 【 Equivalent connection sql99 standard 】
-- Case study 1. Query employee name 、 Department name
SELECT last_name,department_name
from employees e
INNER JOIN departments d
on e.department_id = d.department_id;
-- Case study 2. The query name contains e Name of the employee and type of work
SELECT last_name,job_title
from employees e
INNER JOIN jobs j
on e.job_id = j.job_id
WHERE e.last_name LIKE '%e%';
-- Case study 3. Number of inquiry departments >3 The name of the city and the number of departments ( grouping + Screening )
SELECT city,COUNT(*) Number of departments
from departments d
INNER JOIN locations l
ON d.location_id=l.location_id
GROUP BY city
HAVING COUNT(*)>3;
-- Case study 4. Query the number of employees in which department >3 Department name and number of employees , And in descending order of number ( Add sort )
SELECT department_name,COUNT(*) Number of employees
FROM employees e
INNER JOIN departments d
ON d.department_id = e.department_id
GROUP BY department_name
HAVING COUNT(*)>3
ORDER BY COUNT(*) desc;
---------------------------------------------------------------------------------
-- 【 Non equivalent connection 】
---------------------------------------------------------------------------------
-- 【 Self join 】
-- Case study 5. Query the employee's name and the superior's name
SELECT e.last_name, m.last_name The name of the superior
FROM employees e
JOIN employees m
ON e.`manager_id`= m.`employee_id`;
2、 External connection
Application scenarios : Used to query a table with , The other table doesn't have records
characteristic :
- The query result of external connection is all records in the main table
- If there is a match from the table , The value of the match
- If there is no match from the table , Is displayed null
- External connection query results = Internal connection result + Records that exist in the master table but not in the slave table
- The left outer join ,left join On the left is the main watch
- Right connection ,right join On the right is the main table
- Left outer and right outer exchange the order of two tables , Can achieve the same effect
- Full outer join = The result of internal connection + surface 1 Yes, but the watch 2 No, + surface 2 Yes, but the watch 1 There is no the
-- 1)、 The left outer join :left【outer】
-- Query the names of girls without boyfriends
SELECT b.name
FROM beauty b
LEFT JOIN boys bo
ON b.`boyfriend_id` = bo.`id`
WHERE bo.`id` IS NULL;
-- 2)、 Right connection :right 【outer】
-- Query the names of girls without boyfriends
SELECT b.name
FROM boys bo
RIGHT JOIN beauty b
ON bo.`id` = b.`boyfriend_id`
WHERE bo.`id` IS NULL
-- 3)、 Full outer join :full【outer】
SELECT b.*,bo.*
FROM beauty b
FULL OUTER JOIN boys bo
ON b.`boyfriend_id` = bo.id;
3、 Cross connect :cross
SELECT b.*,bo.*
FROM beauty b
CROSS JOIN boys bo;
版权声明
本文为[Xiaofan Hall]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220610179732.html
边栏推荐
- .NET学习笔记----关于.NET Core那些事(3)【配置文件的读取、json文件的通用解析、读取静态文件】
- Notes on daily development ---- some easy-to-use settings on vs
- Notes on C # daily development ----- obtain all files in the zip in Huawei cloud bucket (including system. Notsupportedexception: "this stream does not support search operation" solution)
- ASP. Net daily development notes ----- WebService server development
- Pixhawk4+Up Board / NUC Implement VIO By Deploying T265
- Digital IC design, after learning Verilog syntax, what else do you need to learn?
- ASP. Net daily development notes ----- JS script executed in the background
- .NET学习笔记(一)----泛型的引入、优势、设计思想、原理、应用
- Nacos persistent switch configuration
- Robomaster Dajiang flying hand assessment
猜你喜欢
随机推荐
PowerJob 工作流
定义一个学生Student类1 获取学生的姓名:get_name() 返回类型:str 2 获取学生的年龄:get_age() 返回类型:int 3 返回3门科目中最高的分数。get_course()
【JEECG】修改Viser图表颜色样式
Notes on daily development ---- some easy-to-use settings on vs
日常开发随手记------VS上一些好用的设置
Install and modify the installation path of utools and vscode plug-ins
ASP.NET日常开发随手记------webService服务端开发
ASP.NET日常开发随手记------用文本文档记录日志
Nacos集群配置
安裝和修改uTools及vscode插件安裝路徑
Zhejiang University Edition "C language programming (3rd Edition)" topic set exercise 7-4 find out the elements that are not common to two arrays
ROS安装及基础与入门
Nacos持久化切换配置
Robomaster大疆飞手考核
Jeecg project deployment notes
Pyhon3 批量合并哔哩哔哩缓存的m4s视频文件
提示用户输入其名字 用户作出响应后 将其名字写 入到文件guest.txt 中 程序判断当不等于n的时候,就执行 创建文件data.txt,文件共10万行,每行存放一个1~100之间的随机一个整数
NOI / 1.5.25:求特殊自然数
送给所有程序员的新年祝福&新年愿望
Powerjob workflow








