1

If I have a select statement like this

SELECT 
   t.time,
   <complicated computation> AS ticks,
   <is it possible to access the value of the ticks row here?> as num
FROM
   MyTable t;

Can I use the calculated value in column 2 as basis for calculations in column 3?

Sh4pe
  • 1,800
  • 1
  • 14
  • 30

1 Answers1

4

You need to wrap this in a subquery: it will look like this:

SELECT
    i.time as time,
    i.ticks as ticks,
    i.ticks + 10 as num
FROM
(
    SELECT 
       t.time as time,
       5 AS ticks
    FROM
       MyTable t
) AS i;
SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304