LetCode-MSSQL从不订购的客户

image.png

解法(1):思路为先查询出订购的客户再使用not in查询出不包含订购客户的其他人也就是从来不订购的客户
查询出订购的客户语句:

select a.Id from Customers as a,Orders as b where b.CustomerId=a.Id

再使用not in 查询 不再里面的客户

select Name as Customers from Customers where Id not in (select a.Id from Customers as a,Orders as b where b.CustomerId=a.Id)  

解法(2):使用左联 查询所有Order表的数据并查询name 为空的数据

select c.Name as Customers from Customers c left join Orders o on c.Id=o.CustomerId where CustomerId is null;
posted @ 2020-04-03 17:31  Bluegoing  阅读(2)  评论(0编辑  收藏  举报  来源