-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
insight_1_products_sold 0236_13062023
- Loading branch information
1 parent
24b564f
commit 09328cb
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- Most often sold products | ||
SELECT DISTINCT ORDERNUMBER, STUFF( | ||
(SELECT ',' + PRODUCTCODE | ||
FROM sales_data AS p | ||
WHERE ORDERNUMBER IN | ||
( | ||
SELECT ORDERNUMBER | ||
FROM | ||
( | ||
SELECT ORDERNUMBER, COUNT(*) AS quantity | ||
FROM sales_data | ||
WHERE STATUS = 'shipped' | ||
GROUP BY ORDERNUMBER | ||
) AS b | ||
WHERE quantity = 9 | ||
) | ||
AND p.ORDERNUMBER = s.ORDERNUMBER | ||
FOR XML PATH('')), 1, 1, '') AS ProductCodes | ||
FROM sales_data AS s | ||
ORDER BY ProductCodes DESC |