[SQL]LeetCode577.員工獎金 | Employee Bonus

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-nlnahjns-me.html 
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html

Select all employee's name and bonus whose bonus is < 1000.git

Table:Employeegithub

+-------+--------+-----------+--------+
| empId |  name  | supervisor| salary |
+-------+--------+-----------+--------+
|   1   | John   |  3        | 1000   |
|   2   | Dan    |  3        | 2000   |
|   3   | Brad   |  null     | 4000   |
|   4   | Thomas |  3        | 4000   |
+-------+--------+-----------+--------+
empId is the primary key column for this table.

Table: Bonus微信

+-------+-------+
| empId | bonus |
+-------+-------+
| 2     | 500   |
| 4     | 2000  |
+-------+-------+
empId is the primary key column for this table.

Example ouput:this

+-------+-------+
| name  | bonus |
+-------+-------+
| John  | null  |
| Dan   | 500   |
| Brad  | null  |
+-------+-------+

選出全部獎金<1000元的僱員姓名及獎金數額spa

Table:Employeecode

+-------+--------+-----------+--------+
| empId |  name  | supervisor| salary |
+-------+--------+-----------+--------+
|   1   | John   |  3        | 1000   |
|   2   | Dan    |  3        | 2000   |
|   3   | Brad   |  null     | 4000   |
|   4   | Thomas |  3        | 4000   |
+-------+--------+-----------+--------+
 此表的主鍵列爲empId。

Table: Bonushtm

+-------+-------+
| empId | bonus |
+-------+-------+
| 2     | 500   |
| 4     | 2000  |
+-------+-------+
 此表的主鍵列爲empId。

Example ouput:blog

+-------+-------+
| name  | bonus |
+-------+-------+
| John  | null  |
| Dan   | 500   |
| Brad  | null  |
+-------+-------+

1 SELECT
2     Employee.name, Bonus.bonus
3 FROM
4     Employee
5         LEFT OUTER JOIN
6     Bonus ON Employee.empid = Bonus.empid
7 ;

 1 # Write your MySQL query statement below
 2 
 3 SELECT
 4     Employee.name, Bonus.bonus
 5 FROM
 6     Employee
 7         LEFT JOIN
 8     Bonus ON Employee.empid = Bonus.empid
 9 WHERE
10     bonus < 1000 OR bonus IS NULL
11 ;
相關文章
相關標籤/搜索