1

there's a way to create an alias after some computation?

in practice there is a better way to write this:

select
    case when aaa ... then then else end AS ALIAS1,
    case when bbb ... then then else end AS ALIAS2,
    case when ccc ... then then else end AS ALIAS3,
    /* the sum of previous aliases */
    case when aaa ... then then else end +
    case when bbb ... then then else end +
    case when ccc ... then then else end AS ALIAS_SUM

thank you in advance

4

1 回答 1

2

你可以做这样的事情。这样你就不会处理两次案件。

SELECT *, ALIAS1 + ALIAS2 + ALIAS3 AS ALIAS_SUM
FROM 
(
    SELECT 
        CASE WHEN aaa ... THEN ... ELSE END AS ALIAS1,
        CASE WHEN bbb ... THEN ... ELSE END AS ALIAS2,
        CASE WHEN ccc ... THEN ... ELSE END AS ALIAS3
    FROM...
) AS casequeries
于 2012-04-09T23:05:30.927 回答