PDA

View Full Version : calculating the sum of similar rows


rocky3023
07-20-06, 06:56 PM
Hello,

Let's say I have 3 columns (my real table will have more, but I don't think that's relevant here). Column 1 is 'date', column 2 is 'name' and column 3 is 'sold'.

Let's say the table has the following records:

'07/18/06','John Smith','2000';
'07/18/06','Jane Doe','1500';
'07/18/06','Jack Jackson','1000';
'07/19/06','John Smith','2000';
'07/19/06','Jane Doe','2000';
'07/19/06','Jack Jackson','3000';
'07/20/06','John Smith','1500';
'07/20/06','Jane Doe','500';
'07/20/06','Jack Jackson','500';

Basically, what I want to do is calculate the sum of column 3 for EVERY PERSON in the table and then display the results in descending order. Is this possible, so that the results would display as follows on a web page?

John Smith 5500
Jack Jackson 4500
Jane Doe 4000

Please help!

mab
07-20-06, 07:25 PM
This should work -
SELECT name, SUM(sold) AS sumation FROM your_table GROUP BY name ORDER BY sumation DESC