访问select语句中的上一个“合成”列

时间:2014-02-19 15:24:47

标签: sql sqlite

如果我有这样的选择语句

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

我可以使用第2列中的计算值作为第3列计算的基础吗?

1 个答案:

答案 0 :(得分:4)

您需要将其包装在子查询中:它将如下所示:

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;