有没有办法根据一个条件生成多于一列?我的看法是这样的:
SELECT
CASE WHEN condition_column = 'condition true' and (condition_column2 = 'condition true' or condition_column3 = 'condition true')
THEN column1 as new_column1
AND column2 as new_column2
AND column3 as new_column3
ELSE column2 as new_column1
AND column3 as new_column2
AND column1 as new_column3
我目前这样做的方法是:
SELECT
CASE WHEN condition_column = 'condition true' and (condition_column2 = 'condition true' or condition_column3 = 'condition true')
THEN column1 ELSE column2 END AS new_column1,
CASE WHEN condition_column = 'condition true' and (condition_column2 = 'condition true' or condition_column3 = 'condition true')
THEN column2 ELSE column3 END AS new_column2,
CASE WHEN condition_column = 'condition true' and (condition_column2 = 'condition true' or condition_column3 = 'condition true')
THEN column3 ELSE column1 END AS new_column3
但是在复杂的情况下,这会变成一个很长的语句列表。