Leetcode SQL 183. 从不订购的客户

  • Post author:
  • Post category:其他


https://leetcode.cn/problems/customers-who-never-order/

使用in

select Name Customers from Customers where 
id not in (select CustomerId from Orders)

664 ms

加上disinct后速度快了很多

select Name Customers from Customers where 
id not in (select distinct CustomerId from Orders)

273 ms

使用exists

select Name Customers from Customers c where 
not exists (select distinct CustomerId from Orders o where o.CustomerId=c.Id)

271 ms

使用join

select c.Name Customers from Customers c 
left join Orders o on o.CustomerId=c.Id
where o.CustomerId is null

555ms



版权声明:本文为u012554509原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。