Re: Aggregate rows in a Table



On Wed, 17 Oct 2007 21:14:13 GMT, Sasikumar wrote:

Hi,

I have a Table with rows as below

A 1 10
B 1 15
A 2 3
A 1 5
A 3 10

Since the 1st & 4th row has values of A & 1 in first & second column, I wanted to aggregate the values in third colum. I wanted the result to be

B 1 15
A 2 3
A 1 15
A 3 10

How can this be done?

SELECT Col1, Col2, SUM(Col3)
FROM SomeTable
GROUP BY Col1, Col2;

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.



Relevant Pages

  • Re: nulls
    ... Hugo Kornelis, SQL Server MVP ... My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis ...
    (comp.databases.ms-sqlserver)
  • Re: T-SQL Challenge
    ... However, for each Product and WE_DATE, we also want the demand units ... Hugo Kornelis, SQL Server MVP ... My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis ...
    (comp.databases.ms-sqlserver)
  • Re: Date Range for SQL 2005
    ... execute. ... Hugo Kornelis, SQL Server MVP ... My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis ...
    (comp.databases.ms-sqlserver)
  • Re: reduce time for search query
    ... Posted by Peso: ... Hugo Kornelis, SQL Server MVP ... My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis ...
    (comp.databases.ms-sqlserver)
  • Re: SQL Minus 7 days from current date
    ... Hugo Kornelis, SQL Server MVP ... My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis ...
    (microsoft.public.sqlserver.mseq)