zoukankan      html  css  js  c++  java
  • mysql left join

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

    Customers 表:

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

    +----+------------+
    | Id | CustomerId |
    +----+------------+
    | 1 | 3 |
    | 2 | 1 |
    +----+------------+
    例如给定上述表格,你的查询应返回:

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

    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/customers-who-never-order
    著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

    SELECT NAME Customers 
    FROM customers A
    LEFT JOIN Orders  B
    ON A.id = B.CustomerId
    WHERE B.id IS NULL
    

    Customers表

    create table `customers` (
    	`id` int (11),
    	`Name` varchar (60)
    ); 
    insert into `customers` (`id`, `Name`) values('1','Joe');
    insert into `customers` (`id`, `Name`) values('2','Henry');
    insert into `customers` (`id`, `Name`) values('3','Sam');
    insert into `customers` (`id`, `Name`) values('4','Max   ');
    
    

    Orders表

    create table `orders` (
    	`Id` int (11),
    	`CustomerId` varchar (60)
    ); 
    insert into `orders` (`Id`, `CustomerId`) values('1','3');
    insert into `orders` (`Id`, `CustomerId`) values('2','1');
    
    
  • 相关阅读:
    Google基本利用
    sqlmap
    kali中wireshark打开后错误
    Python Flask Jinja2模板引擎
    Python Flask学习
    Python 豆瓣日记爬取
    Python 函数装饰器
    Python 生成器
    ss源码学习--从协议建立到完成一次代理请求
    ss源码学习--工作流程
  • 原文地址:https://www.cnblogs.com/mengjianzhou/p/12784877.html
Copyright © 2011-2022 走看看