List:General Discussion« Previous MessageNext Message »
From:Rick James Date:October 3 2012 11:20pm
Subject:RE: Accessing Column Aliases In Other Columns?
View as plain text  
One way:

SELECT  @foo := this + that,
        more_stuff + @foo
    FROM ...;

Another way:

       more_stuff + foo
    FROM (
       SELECT this + that AS foo
          FROM ... ) x;

> -----Original Message-----
> From: Jan Steinman [mailto:Jan@stripped]
> Sent: Wednesday, October 03, 2012 4:09 PM
> To: mysql@stripped
> 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:
> To unsubscribe:

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