我在查询中有一个混叠的case语句,我试图用group-by子句显示它,但我不断得到错误"无效列名(case语句混叠)">
代码Select column 1,
column 2,
column 3,
Case When .... then ...
When .... then ...
When .... then ...
else ... as X
From table1,
table 2,
table 3
where condition 1,
condition 2,
condition 3
group by column 1,
column 2,
X,
column 3;
输出:无效的列名'X'.
您需要在group by子句中包含整个case语句,而不是使用别名。所以
group by column 1,
column 2,
Case When .... then ...
When .... then ...
When .... then ...
else ... ,
column 3;