【MySQL】【leetcode】 Customers Who Never Order解题报告

柔光的暖阳◎ 2022-08-09 09:59 151阅读 0赞

题目

Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.

Table: Customers.

+—-+——-+
| Id | Name |
+—-+——-+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
+—-+——-+
Table: Orders.

+—-+————+
| Id | CustomerId |
+—-+————+
| 1 | 3 |
| 2 | 1 |
+—-+————+
Using the above tables as example, return the following:

+———–+
| Customers |
+———–+
| Henry |
| Max |
+———–+
题目来源:https://leetcode.com/problems/customers-who-never-order/

代码

找出没有买东西的那些人的名字。

  1. # Write your MySQL query statement below
  2. select Name from Customers where Id not in( select t_c.Id from Customers as t_c, Orders as t_o where t_c.Id = t_o.CustomerId );

发表评论

表情:
评论列表 (有 0 条评论,151人围观)

还没有评论,来说两句吧...

相关阅读

    相关 POJ1009解题报告

    保送之后都是项目的事情,一直没有时间写acm题,今天刚好礼拜六尝试着继续之前的工作,争取以后每周能够写上1-2个poj。很久没写算法题感觉自己的智商已经完全不够用了。 说说这

    相关 POJ1007解题报告

    其实就是求线性代数里面所谓的逆序数,既然是逆序数那肯定从后往前计数,通过计算每个字符的逆序数最终算出整个字符串的逆序数。用switch进行条件判断, 比如CAGT,直观上看这