LetCode-MSSQL never orders customers

image.png

Solution (1): The idea is to first query the customer who ordered, and then use not in to query other people who do not include the customer, that is, the customer who has never ordered the customer
query query:

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

Then use not in to query customers who are no longer inside

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)  

Solution (2): Use the left link to query the data of all Order tables and query the data with empty name

select c.Name as Customers from Customers c left join Orders o on c.Id=o.CustomerId where CustomerId is null;
Published 29 original articles · Like 11 · Visits 10,000+

Guess you like

Origin blog.csdn.net/u010840685/article/details/105297675