Given a table customer holding customers information and the referee.

+------+------+-----------+
| id | name | referee_id|
+------+------+-----------+
| 1 | Will | NULL |
| 2 | Jane | NULL |
| 3 | Alex | 2 |
| 4 | Bill | NULL |
| 5 | Zack | 1 |
| 6 | Mark | 2 |
+------+------+-----------+

Write a query to return the list of customers NOT referred by the person with id '2'.

For the sample data above, the result is:

+------+
| name |
+------+
| Will |
| Jane |
| Bill |
| Zack |
+------+

note: 要用 is Null 和 != .

Code

SELECT name FROM customer WHERE referee_id != 2 OR referee_id IS NULL

[LeetCode] 584. Find Customer Referee_Easy tag: SQL的更多相关文章

  1. [LeetCode] 619. Biggest Single Number_Easy tag: SQL

    Table number contains many numbers in column num including duplicated ones.Can you write a SQL query ...

  2. [LeetCode] 620. Not Boring Movies_Easy tag: SQL

    X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a ...

  3. [LeetCode] 176. Second Highest Salary_Easy tag: SQL

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  4. [LeetCode] 196. Delete Duplicate Emails_Easy tag: SQL

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  5. [LeetCode] 603. Consecutive Available Seats_Easy tag: SQL

    Several friends at a cinema ticket office would like to reserve consecutive available seats.Can you ...

  6. [LeetCode] 64. Minimum Path Sum_Medium tag: Dynamic Programming

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  7. [LeetCode] 586. Customer Placing the Largest Number of Orders_Easy tag;SQL

    Query the customer_number from the orders table for the customer who has placed the largest number o ...

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

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

  9. [LeetCode] 181. Employees Earning More Than Their Managers_Easy tag: SQL

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

随机推荐

  1. D - Pagodas

    n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, l ...

  2. php 逗号 explode分割字符串 或 implode组装成字符串

    php 逗号 分割字符串 介绍两个函数给你 <?php //利用 explode 函数分割字符串到数组 $source = "hello1,hello2,hello3,hello4,h ...

  3. 客户端TortoiseSVN的安装及使用方法 (申明:来源于网络)

    客户端TortoiseSVN的安装及使用方法 (申明:来源于网络) 地址:http://blog.chinaunix.net/uid-27004869-id-4112057.html

  4. js callback 和 js 混淆

    function test(a,callback){ a+=100; callback(a) } function abc(a){ a+=100; alert(a); } test(5,abc) js ...

  5. set @sql=N'q',这里的N是什么意思,加与不加有什么区别

    用来支持UNICODE字符的,不加的话,如果sql语句中有Unicode字符会认不出来

  6. CH 3401 - 石头游戏 - [矩阵快速幂加速递推]

    题目链接:传送门 描述石头游戏在一个 $n$ 行 $m$ 列 ($1 \le n,m \le 8$) 的网格上进行,每个格子对应一种操作序列,操作序列至多有 $10$ 种,分别用 $0 \sim 9$ ...

  7. [No0000125]WCF安全体系

    WCF的安全体系主要包括三个方面:传输安全(Transfer Security).授权或者访问控制(Authorization OR Access Control)以及审核(Auditing).而传输 ...

  8. [cloud][sdn] LBaaS/neutron / Octavia

    清晰/浅显: http://www.cnblogs.com/sammyliu/p/4656176.html IBM:写的一般般,价值不大 https://www.ibm.com/developerwo ...

  9. sqlserver binary varbinary image 的区别

    sqlserver binary varbinary image 的区别   binary   固定长度的二进制数据,其最大长度为 8,000 个字节.   varbinary   可变长度的二进制数 ...

  10. delphi加载ADOQUERY

    CxgridDBTableView3.ClearItems;//这里是cxgrid的表层,先清除之前的列再创建  for I:=0 to adoquery1.FieldCount-1 do  begi ...