[LeetCode] 584. Find Customer Referee_Easy tag: SQL

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

原文地址:https://www.cnblogs.com/Johnsonxiong/p/9551557.html

时间: 2024-08-02 08:15:20

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

[LeetCode] 176. Second Highest Salary_Easy tag: SQL

Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ For example, given the above Employee table, the query should return 200 a

[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 emails based on its smallest Id. +----+------------------+ | Id | Email | +----+------------------+ | 1 | [email protected] | | 2 | [email protected]

[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 to find the biggest number, which only appears once. +---+ |num| +---+ | 8 | | 8 | | 3 | | 3 | | 1 | | 4 | | 5 | | 6 | For the sample data above, you

[LeetCode] 126. Word Ladder II_Hard tag: BFS&DFS

Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that: Only one letter can be changed at a time Each transformed word must exist in the word list. Note

[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 values (i.e., change all f values to m and vice versa) with a single update query and no intermediate temp table. For example: | id | name | sex | sala

[LeetCode] 610. Triangle Judgement_Easy tag: SQL

A pupil Tim gets homework to identify whether three line segments could possibly form a triangle. However, this assignment is very heavy because there are hundreds of records to calculate. Could you help Tim by writing a query to judge whether these

[LeetCode] 613. Shortest Distance in a Line_Easy tag: SQL

Table point holds the x coordinate of some points on x-axis in a plane, which are all integers. Write a query to find the shortest distance between two points in these points. | x | |-----| | -1 | | 0 | | 2 | The shortest distance is '1' obviously, w

[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql)

全部最新的题解可以在 我的 github 上找,欢迎 star 和 watch ~ 更新中~~ 说明 这个系列的题解包括用 C++/Java/Python 写的 leetcode 上的算法题目,和 Sql 写的 leetcode 上的数据库题目. 有些题目虽然 AC 了却还没写分析,所以这次就开坑来完成. 链接: 我的 github Leetcode Algorithms Problems Leetcode Database Problems CSDN 题解索引 001.Two_Sum (Med

【LeetCode】未分类(tag里面没有)(共题)

[419]Battleships in a Board (2018年11月25日)(谷歌的题,没分类.) 给了一个二维平面,上面有 X 和 . 两种字符. 一行或者一列连续的 X 代表一个战舰,问图中有多少个战舰.(题目要求one pass, 空间复杂度是常数) 题目说了每两个战舰之间起码有一个 . 作为分隔符,所以不存在正好交叉的情况. 题解:我提交了一个 floodfill 的题解,能过但是显然不满足要求. discuss里面说,我们可以统计战舰的最上方和最左方,从而来统计战舰的个数.(这个