One way:
SELECT @foo := this + that,
more_stuff + @foo
FROM ...;
Another way:
SELECT foo,
more_stuff + foo
FROM (
SELECT this + that AS foo
FROM ... ) x;
> -----Original Message-----
> From: Jan Steinman [mailto:[email protected]]
> Sent: Wednesday, October 03, 2012 4:09 PM
> To: [email protected]
> Subject: Accessing Column Aliases In Other Columns?
>
> I would like to refer to calculated columns in other columns. I thought
> a column alias would do it, but apparently they're only for
> aggregation, like GROUP BY.
>
> Other than repeating the entire calculation, what techniques are
> available for accessing such a calculation?
>
> I'm calculating an electric bill, based on meter readings. I need to
> subtract two meter readings, and use that number in several other
> calculations, for example.
>
> ----------------
> :::: Transformation is not what happens once we've "changed"; it's
> coming out of the dark and seeing what we've got and relating to it
> appropriately and clearly. If we've got a funnel in our hands but we
> think it's a bucket, we're going to keep losing things we value. If we
> know we've got a funnel, then we stick one finger in the hole and use
> it like a bucket to get by in the absence of one. We're "transformed"
> when we fully know who we are - or, even more important, who we are
> not. -- Rick Lewis
> :::: Jan Steinman, EcoReality Co-op ::::
>
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql