PrepAway - Latest Free Exam Questions & Answers

Which Transact-SQL 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 Transact-SQL statement should you use?

PrepAway - Latest Free Exam Questions & Answers

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;

One Comment on “Which Transact-SQL statement should you use?


Leave a Reply