SUM over everything in a GROUP BY
You could, of course, collect the overall sum into variables with one
SELECT, then use those variables in your second SELECT to get the results
you want.
SELECT @SumCash = SUM(cash) FROM tblSales
SELECT store, SUM(cash), SUM(cash) / @SumCash FROM tblSales GROUP BY store
Or you could create a derived table in your FROM clause that returns _one_
row summing the overall values, then cross-joining that row with your other
results.
SELECT a.store, SUM(a.cash), SUM(a.cash) / b.SumCash
FROM tblSales AS a
CROSS JOIN
(SELECT SUM(cash) AS SumCase FROM tblSales) AS b
GROUP BY store
RLF
|