List:General Discussion« Previous MessageNext Message »
From:Jan Steinman Date:October 6 2012 2:18pm
Subject:RE: Accessing Column Aliases In Other Columns?
View as plain text  
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

On 5 Oct 12, at 20:19, mysql-digest-help@stripped wrote:

> From: Rick James <rjames@stripped>
> 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:Jan@stripped]
>> 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
:::: Jan Steinman, EcoReality Co-op ::::

Accessing Column Aliases In Other Columns?Jan Steinman3 Oct
  • RE: Accessing Column Aliases In Other Columns?Rick James3 Oct
RE: Accessing Column Aliases In Other Columns?Jan Steinman6 Oct