Home » RDBMS Server » Server Administration » Sum the same records
Sum the same records [message #374712] Tue, 26 June 2001 04:33 Go to next message
Leonard
Messages: 9
Registered: March 2000
Junior Member
I have a table similiar to the following:
COLA ; COLB
============
AAA ; 123
AAA ; 123
AAA ; 123
AAA ; 155
BBB ; 160
BBB ; 160
CCC ; 155
CCC ; 169

I want to display each record only once as well as total the same record appears in the table. The output should look like this:
COLA ; COLB ; TOTAL
=====================
AAA ; 123 ; 3
AAA ; 155 ; 1
BBB ; 160 ; 2
CCC ; 155 ; 1
CCC ; 169 ; 1

Can someone please help me with the SQL statement to do it?

Thank you!
Re: Sum the same records [message #374713 is a reply to message #374712] Tue, 26 June 2001 04:38 Go to previous messageGo to next message
Arvind L
Messages: 27
Registered: June 2001
Junior Member
The following SQL statement should do,

select COLA,COLB,COUNT(*) FROM

GROUP BY COLA,COLB
Re: Sum the same records [message #374714 is a reply to message #374712] Tue, 26 June 2001 04:41 Go to previous messageGo to next message
Leonard
Messages: 9
Registered: March 2000
Junior Member
Thank you very much!!
Re: Sum the same records [message #374725 is a reply to message #374712] Wed, 27 June 2001 01:15 Go to previous message
Vijay
Messages: 116
Registered: September 1999
Senior Member
select col1,col2,count(*)
from

group by col1,col2
Previous Topic: URGENT : Spooling to a datetime stamp file in MS DOS
Next Topic: Limit records returned by a select
Goto Forum:
  


Current Time: Sat Jul 06 16:04:05 CDT 2024