zoukankan      html  css  js  c++  java
  • LeetCode——Customers Who Never Order(灵活使用NOT IN以及IN)

    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       |
    +-----------+
    

    此题,竟然一时间没想到如何合理的解决方案,主要是有较长的时间没有使用INNOT IN.
    SQL也是一个手熟的活,需要经常锻炼,以下是解题答案:

    # Write your MySQL query statement below
    SELECT Customers.Name AS Customers 
    FROM Customers
    WHERE Customers.Id NOT IN (SELECT CustomerId FROM Orders)
    

    PS:
    如果您觉得我的文章对您有帮助,请关注我的微信公众号,谢谢!
    程序员打怪之路

  • 相关阅读:
    Spring入门
    排序算法【整理】
    C#并发解决(lock)
    Java poi导出word表格
    layui table checkbox默认选中
    Element table表尾合计行嵌入input
    Java接收带List的实体类
    Web SQL Database+mui上传视频
    Web SQL Database+mui上传图片
    mui 上传视频
  • 原文地址:https://www.cnblogs.com/jason1990/p/11645943.html
Copyright © 2011-2022 走看看