sybase中的派生列

时间:2013-04-01 09:41:37

标签: sql view sybase

我正在编写一个查询来定义Sybase Database上的视图。请考虑以下示例

SELECT a, (b+c+d-e) AS derived_1, (b+c+d-e)+2 AS derived_2, (b+c+d-e)+4 as derived_3
FROM TABLENAME

您可以看到我使用某些逻辑(b + c + d-e)计算值,为不同的派生列应用更多逻辑和返回值。有没有什么方法可以写一次(b + c + d-e)?

这样的东西
SELECT a, (b+c+d-e) AS derived_1, derived_1+2 AS derived_2, derived_1+4 as derived_3
FROM TABLENAME

1 个答案:

答案 0 :(得分:1)

将计算包装在子查询中,

SELECT  a, 
        derived_1 + 2 AS derived_2, 
        derived_1 + 4 AS derived_3
FROM
        (
            SELECT  a, (b+c+d-e) AS derived_1 
            FROM    TABLENAME
        ) x