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 |
+-------+-------+ Code
SELECT e.name, b.bonus FROM Employee as e LEFT JOIN Bonus as b ON e.empId = b.empId WHERE b.bonus IS NULL or b.bonus < 1000

# 不能直接用JOIN, 相当于inner join, 如果bonus没有的, 那么就没有了, 所以上面的例子只会输出Dan, 500 这一栏而已.

[LeetCode] 577. Employee Bonus_Easy tag: SQL的更多相关文章

  1. [LeetCode]577. Employee Bonus 员工奖金

    Select all employee's name and bonus whose bonus is < 1000. Table:Employee +-------+--------+---- ...

  2. [LeetCode] 182. Duplicate Emails_Easy tag: SQL

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  3. [LeetCode] 197. Rising Temperature_Easy tag: SQL

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...

  4. [LeetCode] 595. Big Countries_Easy tag: SQL

    There is a table World +-----------------+------------+------------+--------------+---------------+ ...

  5. [LeetCode] 690. Employee Importance_Easy tag: BFS

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  6. [LeetCode] 610. Triangle Judgement_Easy tag: SQL

    A pupil Tim gets homework to identify whether three line segments could possibly form a triangle. Ho ...

  7. [LeetCode] 607. Sales Person_Easy tag: SQL

    Description Given three tables: salesperson, company, orders.Output all the names in the table sales ...

  8. [LeetCode] 627. Swap Salary_Easy tag: SQL

    Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m v ...

  9. [LeetCode] 130. Surrounded Regions_Medium tag: DFS/BFS

    Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A reg ...

随机推荐

  1. H - Farey Sequence

    The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...

  2. mysql中将查询结果进行拼接处理及concat、group_concat的使用

    说明: 本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数1.功能:将多个字符串连接成一个字符串. 2.语法:concat(str1, str2,...) 返回结果为连接参数产 ...

  3. perl 函数

    文档 函数参数 sub hello{ $len = @args = @_; print "hello @args\n"; } hello('ajanuw', 'alone'); # ...

  4. rsync 常用参数

    rsync 常用参数的具体解释如下: -v, --verbose 详细模式输出-q, --quiet 精简输出模式-c, --checksum 打开校验开关,强制对文件传输进行校验-a, --arch ...

  5. [No000011F]Python教程2/9-安装Python 及其解释器介绍

    因为Python是跨平台的,它可以运行在Windows.Mac和各种Linux/Unix系统上.在Windows上写Python程序,放到Linux上也是能够运行的. 要开始学习Python编程,首先 ...

  6. spring @Order标记

    @Order标记定义了组件的加载顺序. @Order标记从spring 2.0出现,但是在spring 4.0之前,@Order标记只支持AspectJ的切面排序.spring 4.0对@Order做 ...

  7. MySQL命令:select查询语句

    SQL 中最常用的 SELECT 语句,用来在表中选取数据. 要记得的知识点如下: SELECT 语句格式: SELECT 要查询的列名 FROM 表名字 WHERE 限制条件: WHERE语句后: ...

  8. strlen函数的汇编实现分析

    [原创][老刘谈算法001]这位运算玩的真溜—strlen函数的汇编实现分析-『密码算法』-看雪安全论坛 https://bbs.pediy.com/thread-229243.htm

  9. MiniHook研究

    git hub 地址: https://github.com/RaMMicHaeL/minhook

  10. python内置函数,lambda表达式,文件读写

    Lambda表达式: lambda是个匿名函数,自动加return返回 a={ 6:2,8:0, 1:4,-5:6,99:11,4:22} print(sorted(a.items()))#按key排 ...