当前位置:网站首页>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
边栏推荐
- C language - stack
- Ten key performance indicators of software applications
- /*Rewrite the program, find the value of the element, and return the iterator 9.13: pointing to the found element. Make sure that the program works correctly when the element you are looking for does
- Analysis function in SQL
- 试题库管理系统–数据库设计[通俗易懂]
- JMeter correlation technology
- Elevator dispatching (pairing project) ①
- DDL language of MySQL database: create, modify alter, delete drop of databases and tables
- [machine] [server] Taishan 200
- software test
猜你喜欢
Quick sort (C language)
Application and Optimization Practice of redis in vivo push platform
Dynamic memory management
Elevator dispatching (pairing project) ④
How do microservices aggregate API documents? This wave of show~
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
Article publishing experiment
Canoe: what is vtsystem
DNS hijacking
Function introduction of canbedded component
随机推荐
Canoe: the fourth simulation project -- bug debugging experience
Discussion | has large AI become autonomous? Lecun, chief scientist of openai
Recursion and divide and conquer strategy
[Galaxy Kirin V10] [desktop] FTP common scene setup
Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13
Elevator dispatching (pairing project) ②
JMeter Foundation
For and while loops
Write a program to define an array with 10 int elements, and take its position in the array as the initial value of each element.
/*Write a function to open the file for input, read the contents of the file into the vector container of string class 8.9: type, and store each line as an element of the container object*/
守护进程Xinted和日志记录Syslogd
Performance features focus & JMeter & LoadRunner advantages and disadvantages
CAPL: on sysVar_ Update difference on sysvar
Interview and lecture summary 1
Remove linked list elements
Knapsack problem and 0-1 knapsack problem
Capl: timer event
Application and Optimization Practice of redis in vivo push platform
Oracle11g | getting started with database. It's enough to read this 10000 word analysis