Wrox Programmer Forums
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2005, 10:58 AM
Authorized User
 
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default distinct sums..

im suck on a query, and cant seem to get arround a mind block.

i have a list

col1 col2
112233 12
112233 13
112233 54
221144 1
221144 10

i need to get the sum of the values in col2 for each distinct value in col1, so for the col1 value of 112233 the col2 sum would be 79 since 12+13+54 = 79

 
Old February 8th, 2005, 11:13 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SELECT SUM(col2)
FROM myTable
Group By col1
 
Old February 8th, 2005, 11:55 AM
Authorized User
 
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks... doh..

 
Old February 9th, 2005, 08:57 AM
Authorized User
 
Join Date: Feb 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deniscuba
Default

try this:
select col1,sum(col2)
from <table>
group by col1






Similar Threads
Thread Thread Starter Forum Replies Last Post
Dividing Two Running Sums in a Report Odeh Naber Access VBA 11 November 7th, 2008 03:45 PM
Using Distinct Smeghead SQL Server 2005 9 December 17th, 2007 11:10 AM
Distinct Eddywardo SQL Server 2005 1 September 2nd, 2006 07:41 AM
Select Distinct? [email protected] SQL Language 5 November 5th, 2005 09:58 AM
Distinct SELECT DISTINCT question... EndEffect Classic ASP Databases 4 August 18th, 2005 08:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.