Skip to content

Instantly share code, notes, and snippets.

@canvural
Created February 5, 2017 18:51
Show Gist options
  • Save canvural/91a6090151c287a054035370c35dab5b to your computer and use it in GitHub Desktop.
Save canvural/91a6090151c287a054035370c35dab5b to your computer and use it in GitHub Desktop.
WITH ProductDiscounts (ProductName, Discount)
AS
(
SELECT p.Name, AVG(so.DiscountPct) as Discount FROM Production.Product p
JOIN Sales.SpecialOfferProduct sop ON p.ProductID = sop.ProductID
JOIN Sales.SpecialOffer so ON so.SpecialOfferID = sop.SpecialOfferID
WHERE so.DiscountPct > 0.0
GROUP BY p.Name
)
SELECT ProductName, (Discount*100) as disc
FROM ProductDiscounts
WHERE (Discount*100) > 15
ORDER BY (Discount*100) DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment