hive查询有条件地插入值

uqxowvwt  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(397)

我有一个 Table1 包含一些黑名单上的名字。现在假设我收到一张唱片 "def" . 配置单元查询应检查 "def" 存在于 Table1 不管怎样。如果不是 name_status 应设置为 blacklisted 否则 null . 名字 "def" 将在两种情况下插入。我面临的问题是,在配置单元中,我们不能在中使用子查询 from 仅适用于条款。
表1

----blacklisted_names------

         "abc"

         "xyz"

---------------------------

表2(接收前) "def" )

---name--|--name_status-----
         |
"abc"    |   blacklisted
         |
         |
----------------------------

表2(收到后) "def" )

---name--|--name_status-----
         |
"abc"    |   blacklisted
         |
"def"    |    null
----------------------------

表2(收到后) "xyz" )

---name--|--name_status-----
         |
"abc"    |   blacklisted
         |
"def"    |    null
         |
"xyz"    |   blaclisted
----------------------------
vm0i2vca

vm0i2vca1#

使用黑名单和用例连接,为连接的行分配“blaclisted”

insert into table2
select n.name,
       case when b.name is not null then 'blacklisted' end as name_status
 from new_rows n
      left join table1 b --blacklisted
                on n.name=b.name

相关问题