Facebook
From Ja, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 138
  1. SELECT Name, ROUND(SUM(Quantity * UnitCost) * 100/TotalSum,2) as Procent
  2. FROM product
  3. INNER JOIN orderdetails ON orderdetails.ProductId = product.Id
  4. INNER JOIN (
  5.     SELECT SUM(Quantity * UnitCost) as TotalSum,
  6.     CategoryId
  7.     FROM orderdetails
  8.     INNER JOIN product ON orderdetails.ProductId = product.Id
  9.     GROUP BY CategoryId) AS Summary ON
  10.     product.CategoryId = Summary.CategoryId
  11.     GROUP BY product.Id,Name,TotalSum;