如果要使用别名,则需要将查询包装在另一个查询中:
SELECT space
, qpr
, space + qpr as result
FROM
(
SELECT
SUM(CASE WHEN rg.category = 'Space' THEN ((rg.score*20)) END) As space,
SUM(CASE WHEN rg.category = 'QPR' THEN ((rg.score*20)) END) As qpr,
(space + qpr) As result
FROM rg_fin As rg JOIN...../*query goes on*/
) x
或者,如果您不需要使用别名,那么您可以重复这些字段:
SELECT
SUM(CASE WHEN rg.category = 'Space' THEN ((rg.score*20)) END) As space,
SUM(CASE WHEN rg.category = 'QPR' THEN ((rg.score*20)) END) As qpr,
(SUM(CASE WHEN rg.category = 'Space' THEN ((rg.score*20)) END)
+ SUM(CASE WHEN rg.category = 'QPR' THEN ((rg.score*20)) END)) As result
FROM rg_fin As rg JOIN...../*query goes on*/