码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode]577. Employee Bonus 员工奖金

时间:2018-09-25 14:09:44      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:left join   employee   col   query   div   ifnull   and   using   prim   

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

Table:Employee

+-------+--------+-----------+--------+
| 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:

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

选出所有奖金<1000元的雇员姓名及奖金数额

解法1:

# Write your MySQL query statement below
SELECT name, bonus 
FROM Employee LEFT JOIN Bonus USING (empId)
WHERE IFNULL(bonus, 0) < 1000  

解法2:

select name, bonus
from 
Employee e left join Bonus b
on e.empId = b.empId
where bonus < 1000 or bonus is null

  

 

[LeetCode]577. Employee Bonus 员工奖金

标签:left join   employee   col   query   div   ifnull   and   using   prim   

原文地址:https://www.cnblogs.com/lightwindy/p/9698931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!