November 14, 2006 at 10:00 pm
Suppose I have a table like the following:
id a b c date
----------------------------------
A123 0 1 2 03Oct06
B123 0 3 2 03Oct06
A123 0 1 5 03Oct06
B123 0 10 6 03Oct06
What I want to do is sum the a, b, c field so that I can get the following table:
id total date
----------------------------------
A123 9 03Oct06
B123 21 03Oct06
How can i do this?
November 14, 2006 at 11:06 pm
select id,'total'=a+b+c,date from table_name
November 14, 2006 at 11:31 pm
It works but this is not a result I want. I think the query should use group by function.
November 15, 2006 at 3:13 am
you are right.. for the correct result there should be a group by clause on the Id and Date.
Cheers
cheers
November 15, 2006 at 3:22 am
November 17, 2006 at 12:03 am
select id, sum (a) + sum(b)+ sum (c) as d from x group by id
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply