Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Sum Query

Status
Not open for further replies.

mlager

Programmer
Sep 1, 2006
74
US
I have a table that looks somthing like below... I'm trying to write a single query that takes each id, sums them up, then prints them out so it looks like the table at the bottom, any advice would be great! Thanks.

id name amt
-- ---- ---
1 John 5.00
1 John 8.00
1 John 10.00
2 Bob 0.00
2 Bob 3.00
3 Joe 6.00
3 Joe 9.00
4 Dave 8.00
4 Dave 2.00
4 Dave 2.00

id name amt
-- ---- ---
1 John 23.00
2 Bob 3.00
3 Joe 15.00
4 Dave 12.00
 
use sum function on the amt column and then group by Id and name

Questions about posting. See faq183-874
 
Code:
SELECT Id, Name, SUM(Amt) AS Amt
       FROM MyTable
GROUP BY Id, Name

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
That response makes make feel stupid, not sure why I was having a mental block on that, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top