如何将这些列的结果连接为最终结果:
SELECT
ID,
CASE
WHEN t1.SCORE <= 10 THEN '2A'
WHEN (t1.SCORE > 20 AND t1.SCORE <= 30) THEN '2B'
WHEN t1.SCORE > 30 THEN '2C'
END AS Result1,
CASE
WHEN t2.POINT <= 10 THEN '2A'
WHEN (t2.POINT > 20 AND t2.POINT <= 30) THEN '2B'
WHEN t2.POINT > 30 THEN '2C'
END AS Result2,
-- CONCAT(Result1,Result2) AS FinalResult
FROM
Table1 t1
INNER JOIN
Table2 t2 ON t2.CustomerID = t1.ID
如何添加这样的表达式:
CONCAT(Result1, Result2) AS FinalResult
将查询打包为派生表:
select Result1, Result2, CONCAT(Result1,Result2) AS FinalResult
from
(
SELECT ID,
CASE
WHEN t1.SCORE <= 10 THEN '2A'
WHEN (t1.SCORE > 20 AND t1.SCORE <= 30) THEN '2B'
WHEN t1.SCORE > 30 THEN '2C'
END AS Result1,
CASE
WHEN t2.POINT <= 10 THEN '2A'
WHEN (t2.POINT > 20 AND t2.POINT <= 30) THEN '2B'
WHEN t2.POINT > 30 THEN '2C'
END AS Result2
FROM Table1 t1 INNER JOIN Table2 t2 ON t2.CustomerID = t1.ID
) dt