当前位置:网站首页>array_ The contains() function uses
array_ The contains() function uses
2022-07-04 10:58:00 【ths512】
One 、array_contains function :
Hive Medium array_contains Function and SQL Medium in keyword The operation is similar to , Used to determine the inclusion (array_contains) Or does not contain (!array_contains) Relationship . And in The difference is array_contains It can be used to judge the same id Whether the same field in multiple records of contains one or more specified values . Pay attention to the consistency of field types , If inconsistent, you need to cast .
grammar :
array_contains( Array , value ), Returns a Boolean value .
Two ,array_contains() Function in where Case in condition
Solve the problem of using too many conditions in a field , The query condition is invalid
select *
from login
where dt='20130101'
and (ver !='3.1' or ver !='3.2'
or ver != '4.0'
or ver != '5.2');
select *
from login
where dt='20130101'
and (ver !='3.1' and ver !='3.2'
and ver != '4.0'
and ver != '5.2');
The purpose of this statement is to login from a user table , Inquire about 20130101 same day , The version is not 3.1,3.2,4.0,5.2 Login user record . however , stay hive0.90 perform , The last thing to come back is 20130101 All login user records of the day , The following query conditions seem to be ignored . Here, it seems that the same field does this kind of multiple != perhaps = The conditions of inquiry , Too much will fail .
So I modified the sentence , as follows :
select *
from login
where dt=20130101
and !array_contains(split('3.1,3.2,4.0,5.2',','),ver);
3、 ... and 、array_contians() Direct application cases :
Use array_contians() Label the monitoring indicators , Judge the alarm level .
select
task_id,
task_code,
task_version,
case
when array_contains(collect_set(tag_id), 599)
or array_contains(collect_set(tag_id), 1225)
then 'L1- Level '
when array_contains(collect_set(tag_id), 600)
or array_contains(collect_set(tag_id), 1226)
then 'L2- Level '
when array_contains(collect_set(tag_id), 601)
or array_contains(collect_set(tag_id), 1240)
then 'L3- Level '
when array_contains(collect_set(tag_id), 1166)
or array_contains(collect_set(tag_id), 1241)
then ' Eagle eye monitoring summary '
else ' Non eagle eye monitoring task '
end as core_tag_name
from
fdm.fdm_buffalo_uniontask_tag_theme_info_new
where
dt = sysdate( - 1)
group by
task_id,
task_code,
task_version
Four 、 Use array_contians() Tag users , In user portrait , Play a role in dimension construction
select
user_id,
count(*) as card_number -- Number of cards used
-- As long as any card is valid, it will be judged as VIP It works ,
case when array_contains(collect_set(status_code),cast(1 as smallint))
then 1
else 0
end AS effective_flag -- Card valid identification
from edw_users.dwd_edw_user_vipcard_df -- user VIP Use the full scale for card purchase
where dt = '${dt}'
and user_id > 0
and deleted_flag = 'N'
group by user_id
边栏推荐
- Canoe: what is vtsystem
- Basic function exercises
- [Galaxy Kirin V10] [server] failed to start the network
- Elevator dispatching (pairing project) ③
- [Galaxy Kirin V10] [server] system partition expansion
- CAPL: on sysVar_ Update difference on sysvar
- 试题库管理系统–数据库设计[通俗易懂]
- Virtual machine configuration network
- Advanced order of function
- Send a request using paste raw text
猜你喜欢

Network connection (III) functions and similarities and differences of hubs, switches and routers, routing tables and tables in switches, why do you need address translation and packet filtering?
![[Galaxy Kirin V10] [desktop] printer](/img/ab/066923f1aa1e8dd8dcc572cb60a25d.jpg)
[Galaxy Kirin V10] [desktop] printer

JMeter common configuration components and parameterization

Function introduction of canbedded component

XMIND installation

Collection of practical string functions

The bamboo shadow sweeps the steps, the dust does not move, and the moon passes through the marsh without trace -- in-depth understanding of the pointer

Linked list operation can never change without its roots

F12 clear the cookies of the corresponding web address

Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
随机推荐
On binary tree (C language)
Dictionaries and collections
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Introduction to Lichuang EDA
Software testing related resources
MBG combat zero basis
Canoe - the third simulation project - bus simulation - 3-2 project implementation
Terms related to hacker technology
Network connection (III) functions and similarities and differences of hubs, switches and routers, routing tables and tables in switches, why do you need address translation and packet filtering?
Personal thoughts on the development of game automation protocol testing tool
The most ideal automated testing model, how to achieve layering of automated testing
2、 Operators and branches
unit testing
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
Canoe - the third simulation project - bus simulation - 3-1 project implementation
Linked list operation can never change without its roots
Digital simulation beauty match preparation -matlab basic operation No. 6
Deepmind proposed a Zuan AI, which specially outputs network attack language