Last active
January 27, 2016 12:50
-
-
Save dnasca/1397bc51ecf1e19b4536 to your computer and use it in GitHub Desktop.
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
--multiple CTEs per statement | |
WITH | |
ProductQty AS ( | |
SELECT | |
ProductId, | |
LocationId, | |
Shelf, | |
Bin, | |
Quantity | |
FROM | |
Production.ProductInventory | |
), | |
ListPriceHistory AS ( | |
SELECT | |
ProductId, | |
StartDate, | |
EndDate, | |
ListPRice | |
FROM | |
Production.ProductListPriceHistory | |
WHERE | |
ListPrice > 10.00 | |
) | |
SELECT | |
p.ProductId, | |
SUM(p.Quantity) AS SumQuantity | |
FROM | |
ProductQty AS p | |
INNER JOIN | |
ListPriceHistory AS lp | |
ON | |
p.ProductId = lp.ProductId | |
GROUP BY | |
p.ProductId; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment