Created
December 25, 2016 12:48
-
-
Save Pzixel/a0697c05814d1a007273c6a35059c492 to your computer and use it in GitHub Desktop.
Returns all products and count of being first customer order for each of these products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH CTE AS | |
( | |
SELECT ProductId, [CustomerOrderNumber] = ROW_NUMBER() OVER(PARTITION BY [CustomerId] ORDER BY [DateCreated]) | |
FROM [Sales] | |
) | |
SELECT ProductId, SUM(IIF(CTE.CustomerOrderNumber = 1, 1, 0)) | |
FROM CTE | |
GROUP BY ProductId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment