当前位置:网站首页>Mysql database learning - Chapter 6 post class exercises of multi table query
Mysql database learning - Chapter 6 post class exercises of multi table query
2022-04-21 18:41:00 【Eat when you're hungry】
MySQL The first 6 Chapter After class exercises of multi table query
1. Show the names of all employees , Department number and department name .
SELECT e.last_name,e.department_id, d.department_name
FROM employees e LEFT OUTER JOIN departments d
ON e.`department_id` = d.`department_id`;
2. Inquire about 90 The staff of department No job_id and 90 Department No location_id
SELECT d.department_id,e.job_id,d.location_id,e.department_id
FROM employees e JOIN departments d
ON e.`department_id` = d.`department_id`
WHERE e.`department_id` = 90;
3. Select all employees with bonuses last_name , department_name , location_id , city
SELECT e.last_name ,d.department_name , d.location_id, city
FROM employees e
LEFT OUTER JOIN departments d
ON e.`department_id` = d.`department_id`
LEFT OUTER JOIN locations l
ON d.`location_id` = l.`location_id`
WHERE commission_pct IS NOT NULL;
4. choice city stay Toronto The employees at work last_name , job_id , department_id , department_name
SELECT e.last_name , e.job_id , e.department_id , d.department_name
FROM employees e
JOIN departments d
ON e.`department_id`=d.`department_id`
JOIN locations l
ON l.`location_id`= d.`location_id`
WHERE l.`city` = 'Toronto';
5. Query the Department name of the employee 、 Department Address 、 full name 、 Work 、 Wages , The Department name of the employee's department is ’Executive’
SELECT e.last_name,e.job_id,e.salary,e.department_id,d.department_name,d.location_id,l.street_address
FROM employees e
join departments d
on e.`department_id` = d.`department_id`
join locations l
on d.`location_id`= l.`location_id`
WHERE d.`department_name` = 'Executive'
6. Select the name of the designated employee , Employee number , And his manager's name and employee number , The result is similar to the following format
employees Emp# manager Mgr#
kochhar 101 king 100
SELECT emp.last_name "employees",emp.employee_id "Emp#",mgr.last_name "manager ",mgr.employee_id "Mgr#"
FROM employees emp
LEFT OUTER JOIN employees mgr
ON emp.`manager_id` = mgr.`employee_id`;
7. Query which departments have no employees ( This question can also be a subquery )

select d.department_id
From departments d
LEFT Join employees e
ON d.`department_id` = e.`department_id`
WHERE e.`department_id` IS NULL;
8. Find out which city has no department

SELECT l.location_id
FROM locations l
left join departments d
on l.`location_id` = d.`location_id`
WHERE d.`location_id` IS NULL;
9. Query department name is Sales or IT Employee information
SELECT e.employee_id,e.last_name,d.department_name
FROM employees e
JOIN departments d
ON e.`department_id`=d.`department_id`
WHERE d.`department_name` = "Sales"
OR d.`department_name` = "IT";
OR
SELECT e.employee_id,e.last_name,d.department_name
FROM employees e
JOIN departments d
ON e.`department_id`=d.`department_id`
WHERE d.`department_name` in ("Sales","IT");
版权声明
本文为[Eat when you're hungry]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211838055970.html
边栏推荐
猜你喜欢

ACM anniversary C language

Win10 uwp asynchronous progress bar

Target penetration exercise 80 momentum: 1

Frida hook variable parameters

redis启动服务和连接客户端

CDF全球调查:软件交付性能停滞不前

Gateway decryption recommended by large manufacturers: introduction to the function module of fizz gateway background management system

零知识证明的潜在价值
After summarizing 30 examples, I realized the layout principle of flutter

找出相等差值的卡片 (20 分) C语言
随机推荐
2021-5-2 question 2 on the second day
What should I do for interface testing? Charles with certificate, what can I do for you?
Collection summary
这玩意叫跳表?
腾讯云数据库TDSQL——博客数据库迁移实践
Target penetration exercise 72-dc4
浅谈Hibernate中的缓存
开发者工具 Top 100 名单
Kotlin | 关于 Lazy ,你应该了解的这些事
[small program] Alipay applet custom pull down refresh component
干货|app自动化测试之Appium 源码修改定制分析
ArrayList && { }
OBS接入网络摄像机
Which immortal wrote 421 pages of advanced notes on MySQL, covering all MySQL technologies! It's so sweet
Where is the initial password for MySQL installation?
C language operator summary
如何查看redis源碼中的 zskiplist 結構
AVL树删除,详细图解
Redis三种特殊数据类型——Geospatial地理空间
Appium principle and jsonwp protocol analysis of automatic testing of dry goods app