Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > SQL SERVER (TECHNET) > SUM over everything in a GROUP BY
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 21st July 01:24
russell fields
External User
 
Posts: 1
Default 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
  Reply With Quote


  sponsored links


2 21st July 01:25
maury markowitzj0r
External User
 
Posts: 1
Default SUM over everything in a GROUP BY



I think I'll try this one, thanks!

Maury
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666