Thanks, Rick!

I had forgotten all about variables for some strange reason...

The subselect isn't nearly as nice as variable, because I'd have to repeat it 
several times.

On 5 Oct 12, at 20:19, mysql-digest-h...@lists.mysql.com wrote:

> From: Rick James <rja...@yahoo-inc.com>
> 
> 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:j...@bytesmiths.com]
>> 
>> 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.
>> 

----------------
:::: I see rejection in my skin, worry in my cancers, bitterness and hate in my 
aching joints. I failed to take care of my mind, and so my body now goes to 
hospital. -- Astrid Alauda
:::: Jan Steinman, EcoReality Co-op ::::


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql

Reply via email to