Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT Production.Product.[Name] AS ProductName, ListPrice,
- Production.ProductSubcategory.[Name] AS ProductSubcategory,
- Production.ProductCategory.[Name] AS ProductCategory,
- [Price Rank] = Row_Number() OVER(ORDER BY ListPrice DESC),
- [Category Price Rank] = Row_Number() OVER(PARTITION BY Production.ProductCategory.[Name] ORDER BY ListPrice DESC),
- [Top 5 Price In Category] =
- CASE
- WHEN ROW_NUMBER() OVER(PARTITION BY Production.ProductCategory.[Name] ORDER BY ListPrice DESC) <= 5 THEN 'Yes'
- ELSE 'No'
- END
- FROM Production.Product
- JOIN Production.ProductSubcategory ON
- Production.Product.ProductSubcategoryID = Production.ProductSubcategory.ProductSubcategoryID
- JOIN Production.ProductCategory ON
- Production.ProductSubcategory.ProductCategoryID = Production.ProductCategory.ProductCategoryID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement