在配置单元中使用多个或 & 和条件时出错
error whlite using multiple or & and conditions in hive
嗨,我有一个 table 如下
temp_layer_table:-
id count name
1 0 v
2 3 r
1 5 t
4 0 f
4 6 g
2 0 r
3 6 r
3 0 g
5 0 t
现在我需要写一个条件,如果 id 是 1 或 4 或 3 并且所有 3 个 id 的计数 = 0,那么我应该消除这些记录
id count name
2 3 r
1 5 t
4 6 g
2 0 r
3 6 r
5 0 t
我尝试了下面的配置单元查询,但没有用
代码 1:-
insert into table final_layer_table
select n.*
from temp_layer_table n
where id = '1'
or id = '4'
or id = '3'
and count != '0' ;
code2:-
insert into table final_layer_table
select n.*
from temp_layer_table n
where id in ('1','4','3')
and count != '0' ;
if id is 1 or 4 or 3 and count = 0 for all 3 ids then i should eliminate those records
我会用 not
条件来表达:
where not (id in (1, 3, 4) and count = 0)
您需要以下任一行:
- id不是1、3、4;或者
- 计数 <> 0。
那就是:
where id not iN (1, 3, 4) or
count <> 0
嗨,我有一个 table 如下 temp_layer_table:-
id count name
1 0 v
2 3 r
1 5 t
4 0 f
4 6 g
2 0 r
3 6 r
3 0 g
5 0 t
现在我需要写一个条件,如果 id 是 1 或 4 或 3 并且所有 3 个 id 的计数 = 0,那么我应该消除这些记录
id count name
2 3 r
1 5 t
4 6 g
2 0 r
3 6 r
5 0 t
我尝试了下面的配置单元查询,但没有用
代码 1:-
insert into table final_layer_table
select n.*
from temp_layer_table n
where id = '1'
or id = '4'
or id = '3'
and count != '0' ;
code2:-
insert into table final_layer_table
select n.*
from temp_layer_table n
where id in ('1','4','3')
and count != '0' ;
if id is 1 or 4 or 3 and count = 0 for all 3 ids then i should eliminate those records
我会用 not
条件来表达:
where not (id in (1, 3, 4) and count = 0)
您需要以下任一行:
- id不是1、3、4;或者
- 计数 <> 0。
那就是:
where id not iN (1, 3, 4) or
count <> 0