美文网首页
leetcode中的SQL题(七)

leetcode中的SQL题(七)

作者: 瓜皮小咸鱼 | 来源:发表于2019-04-03 10:48 被阅读0次

某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。
Customers 表:

+----+-------+
| Id | Name  |
+----+-------+
| 1  | Joe   |
| 2  | Henry |
| 3  | Sam   |
| 4  | Max   |
+----+-------+

Orders 表:

+----+------------+
| Id | CustomerId |
+----+------------+
| 1  | 3          |
| 2  | 1          |
+----+------------+

例如给定上述表格,你的查询应返回:

+-----------+
| Customers |
+-----------+
| Henry     |
| Max       |
+-----------+

答案:

select name customers from customers 
where id not in (select CustomerId from Orders );

相关文章

  • leetcode中的SQL题(七)

    某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客...

  • leetcode中的SQL题(三)

    编写一个 SQL 查询,获取 Employee 表中第 n 高的薪水(Salary)。 例如上述 Employee...

  • leetcode中的SQL题(十三)

    给定一个 salary 表,如下所示,有 m=男性 和 f=女性 的值 。交换所有的 f 和 m 值(例如,将所有...

  • leetcode中的SQL题(八)

    Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id D...

  • leetcode中的SQL题(五)

    Employee 表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id...

  • leetcode中的SQL题(十)

    编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个。 在...

  • leetcode中的SQL题(四)

    编写一个 SQL 查询来实现分数排名。如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次...

  • leetcode中的SQL题(九)

    Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id 。...

  • leetcode中的SQL题(十一)

    给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id。 ...

  • leetcode中的SQL题(十二)

    Trips 表中存所有出租车的行程信息。每段行程有唯一键 Id,Client_Id 和 Driver_Id 是 U...

网友评论

      本文标题:leetcode中的SQL题(七)

      本文链接:https://www.haomeiwen.com/subject/obdabqtx.html