【发布时间】:2014-01-02 09:05:49
【问题描述】:
我有一个类似下面的代码
SELECT SUM(points_1) AS total_points_1, SUM(points_2) AS total_points_2,
total_points_1 +
CASE
WHEN total_points_1 BETWEEN 50 AND 100 THEN 50
WHEN total_points_1 BETWEEN 100 AND 200 THEN 100
WHEN total_points_1 BETWEEN 200 AND 300 THEN 200
WHEN total_points_1 BETWEEN 300 AND 400 THEN 300
ELSE 500
END AS another_row_1,
total_points_2 +
CASE
WHEN total_points_2 BETWEEN 50 AND 100 THEN 50
WHEN total_points_2 BETWEEN 100 AND 200 THEN 100
WHEN total_points_2 BETWEEN 200 AND 300 THEN 200
WHEN total_points_2 BETWEEN 300 AND 400 THEN 300
ELSE 500
END AS another_row_2,
FROM `table`
我的目标是将another_row_1 和another_row_2 的结果相加
我尝试在END AS another_row_2, 之后立即执行以下行,但没有成功
SUM(another_row_1 + another_row_2) AS total_sum
【问题讨论】:
-
another_row_1和another_row_2是列投影,而不是行。因此,您只需使用+运算符添加它们 -
你打算怎么做?
标签: php mysql sql if-statement case