Created
February 5, 2017 18:51
-
-
Save canvural/91a6090151c287a054035370c35dab5b 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
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