Query help!

  • Thread starter Thread starter deercreek
  • Start date Start date
D

deercreek

Is there a way to sum a specific column in a query? What I have is a
query that pulls several line based on a id field. I want to total just
1 column in the query and have it report back as new column. Example

Id Site price date
101 201 40.00 1-11-05
101 404 25.00 1-11-05
101 600 15.00 1-11-05

and I would like to create a new column for total price that would show


Id Site price date totalprice
101 201 40.00 1-11-05 80.00
101 404 25.00 1-11-05 80.00
101 600 15.00 1-11-05 80.00

Can someone explain how to do that? Thanks for help!
 
Hope this works for you:

SELECT tablename.Id, tablename.Site, tablename.price, tablename.date,
t2.totalprice
FROM (SELECT Id, Sum(price) as totalprice
FROM tablename
GROUP BY id) t2
RIGHT JOIN tablename ON t2.Id = tablename.Id;

If there's an error in the FROM clause, you may need to create two separate
queries.

Jay
 
Back
Top