在“where”子句中使用新列

sds*_*sds 4 sql hive

hive拒绝此代码:

select a, b, a+b as c
from t
where c > 0
Run Code Online (Sandbox Code Playgroud)

Invalid table alias or column reference 'c'

我真的需要写一些类似的东西吗

select * from 
(select a, b, a+b as c
 from t)
where c > 0
Run Code Online (Sandbox Code Playgroud)

编辑:

  1. 它的计算c足够复杂,我不想重复它where a + b > 0
  2. 我需要一个适用于的解决方案hive

Cam*_*uce 5

如果要使用派生列,请使用公用表表达式。

with x as
(
select a, b, a+b as c
from t
)
select * from x where c >0
Run Code Online (Sandbox Code Playgroud)