Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.59 KB | None | 0 0
  1. SELECT isnull(c.Name, '') "Nazwa", isnull(CAST(YEAR(sod.ModifiedDate) AS NCHAR), '') "Rok",
  2. CAST(round(100 * SUM(sod.LineTotal) /
  3. (SUM(SUM(sod.LineTotal)) OVER(partition BY c.ProductCategoryID)), 2) AS DECIMAL(10,2)) "Procent"
  4. FROM Sales.SalesOrderDetail sod JOIN Production.Product p ON sod.ProductID = p.ProductID
  5. JOIN Production.ProductSubcategory sc ON p.ProductSubcategoryID = sc.ProductSubcategoryID
  6. JOIN Production.ProductCategory c ON sc.ProductCategoryID = c.ProductCategoryID
  7. WHERE c.Name = 'Bikes'
  8. GROUP BY GROUPING sets((c.Name, YEAR(sod.ModifiedDate), c.ProductCategoryID), ())
  9. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement