当前位置:网站首页>Database daily question --- day 9: salesperson
Database daily question --- day 9: salesperson
2022-06-11 21:20:00 【InfoQ】
One 、 Problem description
SalesPerson+-----------------+---------+
| Column Name | Type |
+-----------------+---------+
| sales_id | int |
| name | varchar |
| salary | int |
| commission_rate | int |
| hire_date | date |
+-----------------+---------+
sales_id Is the primary key column of the table .
Each row of the table shows the salesperson's name and ID , And their wages 、 Commission rate and date of employment .
Company+-------------+---------+
| Column Name | Type |
+-------------+---------+
| com_id | int |
| name | varchar |
| city | varchar |
+-------------+---------+
com_id Is the primary key column of the table .
Each row of the table indicates the name of the company and ID , And the city where the company is located .
Orders+-------------+------+
| Column Name | Type |
+-------------+------+
| order_id | int |
| order_date | date |
| com_id | int |
| sales_id | int |
| amount | int |
+-------------+------+
order_id Is the primary key column of the table .
com_id yes Company In the table com_id The foreign key .
sales_id It's from the salesperson table sales_id The foreign key .
Each row of the table contains the information of an order . This includes the company's ID 、 Salesperson's ID 、 Date of order and amount paid .
Two 、 Subject requirements
Examples
Input :
SalesPerson surface :
+----------+------+--------+-----------------+------------+
| sales_id | name | salary | commission_rate | hire_date |
+----------+------+--------+-----------------+------------+
| 1 | John | 100000 | 6 | 4/1/2006 |
| 2 | Amy | 12000 | 5 | 5/1/2010 |
| 3 | Mark | 65000 | 12 | 12/25/2008 |
| 4 | Pam | 25000 | 25 | 1/1/2005 |
| 5 | Alex | 5000 | 10 | 2/3/2007 |
+----------+------+--------+-----------------+------------+
Company surface :
+--------+--------+----------+
| com_id | name | city |
+--------+--------+----------+
| 1 | RED | Boston |
| 2 | ORANGE | New York |
| 3 | YELLOW | Boston |
| 4 | GREEN | Austin |
+--------+--------+----------+
Orders surface :
+----------+------------+--------+----------+--------+
| order_id | order_date | com_id | sales_id | amount |
+----------+------------+--------+----------+--------+
| 1 | 1/1/2014 | 3 | 4 | 10000 |
| 2 | 2/1/2014 | 4 | 5 | 5000 |
| 3 | 3/1/2014 | 1 | 1 | 50000 |
| 4 | 4/1/2014 | 1 | 4 | 25000 |
+----------+------------+--------+----------+--------+
Output :
+------+
| name |
+------+
| Amy |
| Mark |
| Alex |
+------+
explain :
According to the table orders Order in '3' and '4' , It's easy to see that there is only 'John' and 'Pam' Two salesmen once told the company 'RED' Sold .
So we need output meters salesperson The names of all the others in .
Investigate
1. Query statement 、 Connection problem
2. It is recommended to use time 10~25min
3、 ... and 、 Problem analysis
1. Subquery
Company and Orders idSalesPerson2. Left connection
left join sentence | order_id | date | com_id | sales_id | amount | com_id | name | city |
|----------|----------|--------|----------|--------|--------|------|--------|
| 3 | 3/1/2014 | 1 | 1 | 50000 | 1 | RED | Boston |
| 4 | 4/1/2014 | 1 | 4 | 25000 | 1 | RED | Boston |
SalesPersonsales_id Four 、 coded
1. Subquery
select s.name
from SalesPerson s
where s.sales_id not in
(
select o.sales_id
from Company c,Orders o
where c.name='RED' and c.com_id=o.com_id
)
2. Left connection
select s.name
from SalesPerson s
where s.sales_id not in
(
select o.sales_id
from Orders o
left join Company c on c.com_id=o.com_id
where c.name='RED'
)
5、 ... and 、 test result



边栏推荐
- Teach you how to use win7 system to quickly build your own website
- I haven't blogged for two months. I sent an article to prove that my account is still alive
- Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
- Flutter implements the JD address selection component
- 技术交流|网络安全设备为什么要用Bypass功能
- JVM heap
- Brain cell membrane equivalent neural network training code
- Work assessment of spectral analysis of Jilin University in March of the 22nd spring -00079
- Solve the problem of img 5px spacing
- Website online customer service system Gofly source code development log - 2 Develop command line applications
猜你喜欢

Goland中在文件模板中为go文件添加个人声明

Part II data link layer
![[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions](/img/1f/00f2085186971198928b012a3792ea.jpg)
[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions

【 C Advanced language】 Integer Storage in Memory

Docker installing MySQL

Explanation of each column output by explain statement

【C語言進階】整型在內存中的存儲

php pcntl_fork 创建多个子进程解析

One article to show you how to understand the harmonyos application on the shelves

Weekly 02 | to tell you the truth, I am actually a student of MIT
随机推荐
IDEA中,运行yarn命令,显示无法加载文件,因为在此系统上禁用运行脚本
Flutter implements the JD address selection component
2022年6月9日 16:29:41 日记
一个Golang的私有库设置问题
俩月没发过博客了,发一篇证明自己的账号还活着
Redis fourth session - redis high performance principle (multiplexing) and high availability analysis (backup, master-slave)
Stream Chinese sorting
table_ Display status
Realize the same length of tablayout subscript and text, and change the selected font size
电竞网咖用2.5G网卡,体验飞一般的感觉!
Ubantu1804 two opencv versions coexist
Only 38 years old! Zhou Chuan, a researcher of the Chinese Academy of Sciences, died unfortunately. Rao Yi sent a document to mourn: he guided me when he was still my student
How to manually drag nodes in the Obsidian relationship graph
Notes on the preload method of Gorm
Brain cell membrane equivalent neural network training code
[Game Theory - introduction]
第二部分 数据链路层
RANSAC extraction plane (matlab built-in function)
从概率论基础出发推导卡尔曼滤波
JVM method area