Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[gray]-- slower[/gray]
[b]select[/b]
col1,col2,(
[b]select[/b]
max(col1-col2)
[b]from[/b] thetable
) maxvalue
[b]from[/b] thetable
[gray]-- faster[/gray]
[b]select[/b]
col1,col2,maxvalue
[b]from[/b] thetable
,(
[b]select[/b]
max(col1-col2) maxvalue
[b]from[/b] thetable
) foo
select
col1,col2,maxvalue[red],maxvalue-col1[/red]
from thetable
,(
select
max(col1-col2) maxvalue
from thetable
) foo
Your code did not worked because you tried to use an alias in an expression in the same [tt]select[/tt]'s field list where the alias itself is defined. My code worked because I defined the alias in the inner [tt]select[/tt] and used it only in the outer [tt]select[/tt], not in the same one. If this was the question...kaptlid said:do I have to declare the field name before I use it in the query or subquery?