Subject | Use of column aliases in a SELECT |
---|---|
Author | Josef Kokeš |
Post date | 2012-01-27T10:46:51Z |
Hi!
I find myself repeatedly writing code such as
SELECT (a+b)*c AS value1,
some_function((a+b)*c) AS value2,
some_other_function((a+b)*c) AS value 3
FROM ...
Is there any other way to "reuse" a calculated value by referencing its
alias than through views? E.g.
CREATE VIEW valueview AS SELECT SELECT (a+b)*c AS value1 FROM ...
SELECT value1, some_function(value1) AS value2 ...
I know I can reference the column by its position in GROUP BY, but I
need to reference it in the field list as well as in the WHERE condition.
Thanks,
Pepak
I find myself repeatedly writing code such as
SELECT (a+b)*c AS value1,
some_function((a+b)*c) AS value2,
some_other_function((a+b)*c) AS value 3
FROM ...
Is there any other way to "reuse" a calculated value by referencing its
alias than through views? E.g.
CREATE VIEW valueview AS SELECT SELECT (a+b)*c AS value1 FROM ...
SELECT value1, some_function(value1) AS value2 ...
I know I can reference the column by its position in GROUP BY, but I
need to reference it in the field list as well as in the WHERE condition.
Thanks,
Pepak