0

Say I have a query that goes like this

select column1
,column2
,column3
,column4
,column5 + reusethiscolumn as Reusethiscolumn2

[can i use here the data that will be derived from the column below?]

,case[computation here] as reusethiscolumn
from table

is there any way to do this? thanks in advance.

Radu Gheorghiu
  • 20,049
  • 16
  • 72
  • 107
igarren
  • 37
  • 2
  • 13
  • It is possible , to provide solution give some data and result – Azar Jun 27 '14 at 08:04
  • Possible duplicate of http://stackoverflow.com/questions/6591183/t-sql-column-alias-on-computed-column-invalid-column-name – VMai Jun 27 '14 at 08:13
  • No, you can't use a column alias at this point without using a subselect. You can use a column alias in the `ORDER BY` clause, see column_alias can be used in an ORDER BY clause. MySQL extends the use of column alias names to the `HAVING` and `GROUP BY` clauses – VMai Jun 27 '14 at 08:16
  • SQL processes all columns in the `SELECT` clause "as if" they're all being evaluated in parallel - this means that within a single `SELECT` clause, you can't have one column's computation rely upon a different column's value – Damien_The_Unbeliever Jun 27 '14 at 08:32

1 Answers1

1
select 
column1
,column2
,column3
,column4
,(column5 + reusethiscolumn) as Reusethiscolumn2
from
(
  select 
    column1
   ,column2
   ,column3
   ,column4
   ,column5
   ,case[computation here] as reusethiscolumn
  from table
) AS SubQ
Vigi Tri
  • 156
  • 10