[LeetCode]-DataBase-Customers Who Never Order
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 |
+-----------+ 需求:查询没下单的客户 查询:
CREATE TABLE Customers(
Id TINYINT UNSIGNED,
Name VARCHAR(20)
)ENGINE=MyISAM CHARSET=utf8;
CREATE TABLE Orders(
Id TINYINT UNSIGNED,
CustomerId TINYINT UNSIGNED
)ENGINE=MyISAM CHARSET=utf8;
SELECT t1.Name
FROM Customers t1
WHERE NOT EXISTS(
SELECT * FROM Orders t2 WHERE t2.CustomerId=t1.Id
)
[LeetCode]-DataBase-Customers Who Never Order的更多相关文章
- LeeCode(Database)-Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- DataBase -- Customers Who Never Order
Question: Suppose that a website contains two tables, the Customers table and the Orders table. Writ ...
- LeetCode 183. Customers Who Never Order (从不订购的客户)
题目标签: 题目给了我们 Customers 和 Orders 两个表格,让我们找到 从没订购过的客户. 首先从Orders 得到 订购过的CustomerId,然后再去Customers 里找 没有 ...
- leetcode 183. Customers Who Never Order
select Name as Customers from Customers where Id not in (select CustomerId from Orders);
- [LeetCode] Customers Who Never Order 从未下单订购的顾客
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- LeetCode - Customers Who Never Order
Description: Suppose that a website contains two tables, the Customers table and the Orders table. W ...
- 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 qu ...
- [SQL]LeetCode183. 从不订购的客户 | Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- LeetCode Database题解
175. Combine Two Tables 使用外连接即可. # Write your MySQL query statement below select FirstName, LastName ...
- [LeetCode] 429. N-ary Tree Level Order Traversal_ Easy
Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
随机推荐
- .net几种timer区别
概述:.net框架不同名称控件都包含了各种timer,但每个timer有什么具体区别呢? 一.System.Threading private static void ThreadingTimer() ...
- java io 文件读写操作
写: import java.io.*; String filePath= "F:\\test.txt"; FileWriter fwriter = null; fwriter = ...
- 请求转发forward()和URL重定向redirect()的区别
- php强大的filter过滤用户输入
<?php $filters = array //定义过滤的数组 ( "name" => array ( "filter"=>FILTER_S ...
- Linux设置静态IP后出现的几种问题
一.设置静态IP后无法重启网卡 如下图所示 原因分析:control process exited with error code.控制进程存在错误代码. 解决方案:可以检查网卡配置文件是否修改错误. ...
- 用python实现js语言里的特性
有大佬说:“搜 arraybuffer 的 polyfill 然后翻译成 python就行了” ...
- scrapy 运行时报错 No module named _sqlite3
新服务器上运行scrapy时报错 exceptions.ImportError: No module named _sqlite3 原因 由于新的环境缺少sqlite的依赖,编译python3是虽然不 ...
- apache 部署
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.localhost DocumentRoot "D:/EmpireServ ...
- PAT Basic 1066 图像过滤 (15 分)
图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来.现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换. 输入格式: 输入在第一行给出一幅图像的分辨 ...
- 【洛谷P2447】外星千足虫
题目大意:给定一个 M 个含 N 个未知数的异或方程组,保证有解,若存在唯一解,给出至少需要几个方程才能得出唯一解,若不存在,直接输出不存在. 题解:异或方程组也满足类似初等行变换的操作,只不过所有的 ...