Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of hive conditional function

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "the usage of hive conditional function". In daily operation, I believe many people have doubts about the usage of hive conditional function. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "the usage of hive conditional function". Next, please follow the editor to study!

Conditional function

1. If function: if

Syntax: if (boolean testCondition, T valueTrue, T valueFalseOrNull)

Return value: t

Note: when the condition testCondition is TRUE, return valueTrue; otherwise return valueFalseOrNull

For example:

Hive > select if (1x 2100200) from lxw_dual

two hundred

Hive > select if (1mm 1100200) from lxw_dual

one hundred

two。 Non-empty lookup function: COALESCE

Syntax: COALESCE (T v1, T v2, …)

Return value: t

Description: returns the first non-null value in the parameter; if all values are NULL, return NULL

For example:

Hive > select COALESCE (null,'100','50') from lxw_dual

one hundred

3. Conditional judgment function: CASE

Syntax: CASE a WHEN b THEN c [WHEN d THEN e] * [ELSE f] END

Return value: t

Note: if an equals b, return c; if an equals d, return e; otherwise return f

For example:

Hive > Select case 100 when 50 then 'tom' when 100 then' mary'else 'tim' end from lxw_dual

Mary

Hive > Select case 200 when 50 then 'tom' when 100 then' mary'else 'tim' end from lxw_dual

Tim

4. Conditional judgment function: CASE

Syntax: CASE WHEN a THEN b [WHEN c THEN d] * [ELSE e] END

Return value: t

Note: returns b if an is TRUE, d if c is TRUE, and e otherwise

For example:

Hive > select case when 1: 2 then 'tom' when 2: 2 then' mary' else'tim' end from lxw_dual

Mary

Hive > select case when 1'1 then 'tom' when 2' 2 then 'mary' else'tim' end from lxw_dual

Tom

At this point, the study of "the usage of hive conditional function" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report