Skip to content

Instantly share code, notes, and snippets.

@dnasca
Last active January 27, 2016 12:50
Show Gist options
  • Save dnasca/1397bc51ecf1e19b4536 to your computer and use it in GitHub Desktop.
Save dnasca/1397bc51ecf1e19b4536 to your computer and use it in GitHub Desktop.
--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