Which TransactSQL statement should you use?

You have a table named Sales. You are tasked to list products that have been sold to less than ten
customers.
You need to write a query to achieve the task.
Which TransactSQL
statement should you use?

You have a table named Sales. You are tasked to list products that have been sold to less than ten
customers.
You need to write a query to achieve the task.
Which TransactSQL
statement should you use?

A.
SELECT ProductID,
COUNT(*) AS CustomerCount
FROM Sales
GROUP BY ProductID, CustomerID
HAVING COUNT(*) < 10;

B.
SELECT ProductID,
COUNT(DISTINCT CustomerID) AS CustomerCount
FROM Sales
GROUP BY ProductID
HAVING COUNT(DISTINCT CustomerID) < 10;

C.
SELECT ProductID, CustomerID,
COUNT(DISTINCT CustomerID) AS CustomerCount
FROM Sales
GROUP BY ProductID, CustomerID
HAVING COUNT(DISTINCT CustomerID) < 10;

D.
SELECT *
FROM
(SELECT ProductID, RANK() OVER (ORDER BY CustomerID DESC) AS Rnk
FROM Sales) s
WHERE s.Rnk <= 10;



Leave a Reply 0

Your email address will not be published. Required fields are marked *