183-从不订购的客户
从不订购的客户
- 题目如下所示
个人题解
很简单,如下 SQL 所示
-
-- 建表 CREATE TABLE 183_customers( Id INT PRIMARY KEY, Name VARCHAR(10) ); CREATE TABLE 183_orders( Id INT PRIMARY KEY, CustomerId INT ); -- 从不订购的客户,即在订单表上从未出现过的 CustomerId SELECT c.`Name` Customers FROM 183_customers c WHERE c.Id NOT IN (SELECT o.CustomerId FROM 183_orders o);