July 17, 2009 at 4:36 pm
How can I re-use the value of column three below?
select col1,col2,sum(col1+col2) as col3
from
table
group by col1,col2
I would like to add something like this:
select col1,col2,sum(col1+col2) as col3, col3/2
Thanks for any guidance.
July 17, 2009 at 4:43 pm
I would like to add something like this:
select col1,col2,sum(col1+col2) as col3, col3/2
ARE YOU TRYING TO DIVIDE COL3 BY COL2?
IF SO, TRY THIS:
SELECT COL1, COL2, SUM(COL1 + COL2) AS COL3, SUM(COL3/COL2) AS COL4
July 17, 2009 at 4:51 pm
I get an INVALID COLUMN name when doing that. it seems to not recognize that COL3 should now be considered a column. Note, COL3 is not really part of the table, rather it would only be displayed based on results of col1+col2.
thanks
July 18, 2009 at 2:09 am
Hi,
try this
01)
select col1,col2,sum(col1+col2) as col3, (sum(col1+col2)/2)as Col4
from MYTABLE
group by col1,col2
02)
select *,(col3/2)as col4 from
(
select col1,col2,sum(col1+col2) as col3
from MYTABLE
group by col1,col2
) AS X
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply