Friday, May 31, 2024

SQL Server Scenario Based Interview Question - 3

There is a database which contains below tables.

Product

Customer

1. Write a query which shows the count for each Products.

Select 

P.Name,
count(C.CID)
From 
@Product P
left join @Customer C on C.PID = P.PID
Group by
P.Name

2. Write a query which shows the Product which doesn't have any customer.

Select 
Name 
From 
@Product 
Where 
PID not in (select distinct PID from @Customer where PID is not null)









 

No comments:

Post a Comment