我有这样的SQL:
select case when.....end as colA, table2.col3
from table1
join table2 on table2.colB = colA
在if语句的情况下,还有一些其他的表列,这可行吗?我有错误说colA无效。
答案 0 :(得分:0)
where
或on
子句中未理解列别名。
您可以使用子查询执行此操作,假设case
仅涉及table1
中的列:
select case when.....end as colA, t2.col3
from (select table1.*, (case when.....end) as colA
from table1
) t1 join
table2 t2
on t2.colB = t1.colA;
否则,您可以将case
语句放在on
子句中:
select case when.....end as colA, t2.col3
from (select table1.*, (case when.....end) as colA
from table1
) t1 join
table2 t2
on t2.colB = ( case when.....end );