如何更改此SELECT
语句以创建adj_b2
列,该列取决于与adj_a2
相同的条件和取决于不同条件的adj_b3
?< / p>
SELECT CASE
WHEN c.1 > 5
THEN COALESCE(a.2,0)*2
ELSE COALESCE(a.2,0)
END as adj_a2, a.*, b.*, c.*
答案 0 :(得分:0)
您只需使用三个单独的CASE
语句:
SELECT
CASE
WHEN c.1 > 5
THEN COALESCE(a.2,0)*2
ELSE COALESCE(a.2,0)
END as adj_a2,
CASE
WHEN c.1 > 5
THEN COALESCE(b.2,0)*2
ELSE COALESCE(b.2,0)
END as adj_b2,
CASE
WHEN c.2 < 42
THEN COALESCE(a.2,0)*c.3
ELSE COALESCE(b.2,0)*c.4
END as adj_b3,
a.*,
b.*,
c.*