zoukankan      html  css  js  c++  java
  • hive函数之~关系运算

    1、等值比较: =

    语法:A=B
    操作类型:所有基本类型
    描述: 如果表达式A与表达式B相等,则为TRUE;否则为FALSE

    hive> select 1 from tableName where 1=1;

    2、不等值比较: <>

    语法: A <> B
    操作类型: 所有基本类型
    描述: 如果表达式A为NULL,或者表达式B为NULL,返回NULL;如果表达式A与表达式B不相等,则为TRUE;否则为FALSE

    hive> select 1 from tableName where 1 <> 2;

    3、小于比较: <

    语法: A < B
    操作类型:所有基本类型
    描述: 如果表达式A为NULL,或者表达式B为NULL,返回NULL;如果表达式A小于表达式B,则为TRUE;否则为FALSE

    hive> select 1 from tableName where 1 < 2;

    4、小于等于比较: <=

    语法: A <= B
    操作类型: 所有基本类型
    描述: 如果表达式A为NULL,或者表达式B为NULL,返回NULL;如果表达式A小于或者等于表达式B,则为TRUE;否则为FALSE

    hive> select 1 from tableName where 1 < = 1;

    5、大于比较: >

    语法: A > B
    操作类型: 所有基本类型
    描述: 如果表达式A为NULL,或者表达式B为NULL,返回NULL;如果表达式A大于表达式B,则为TRUE;否则为FALSE

    hive> select 1 from tableName where 2 > 1;

    6、大于等于比较: >=

    语法: A >= B
    操作类型: 所有基本类型
    描述: 如果表达式A为NULL,或者表达式B为NULL,返回NULL;如果表达式A大于或者等于表达式B,则为TRUE;否则为FALSE

    hive> select 1 from tableName where 1 >= 1;

    1

    注意:String的比较要注意(常用的时间比较可以先 to_date 之后再比较)

    hive> select * from tableName;

    OK

    2011111209 00:00:00     2011111209

    hive> select a, b, a<b, a>b, a=b from tableName;

    2011111209 00:00:00     2011111209      false   true    false

    7、空值判断: IS NULL

    语法: A IS NULL
    操作类型: 所有类型
    描述: 如果表达式A的值为NULL,则为TRUE;否则为FALSE

    hive> select 1 from tableName where null is null;

    8、非空判断: IS NOT NULL

    语法: A IS NOT NULL
    操作类型: 所有类型
    描述: 如果表达式A的值为NULL,则为FALSE;否则为TRUE

    hive> select 1 from tableName where 1 is not null;

    9、LIKE比较: LIKE

    语法: A LIKE B
    操作类型: strings
    描述: 如果字符串A或者字符串B为NULL,则返回NULL;如果字符串A符合表达式B 的正则语法,则为TRUE;否则为FALSE。B中字符”_”表示任意单个字符,而字符”%”表示任意数量的字符。

    hive> select 1 from tableName where 'football' like 'foot%';

    hive> select 1 from tableName where 'football' like 'foot____';

    <strong>注意:否定比较时候用NOT A LIKE B</strong>

    hive> select 1 from tableName where NOT 'football' like 'fff%';

    10、JAVA的LIKE操作: RLIKE

    语法: A RLIKE B
    操作类型: strings
    描述: 如果字符串A或者字符串B为NULL,则返回NULL;如果字符串A符合JAVA正则表达式B的正则语法,则为TRUE;否则为FALSE。

    hive> select 1 from tableName where 'footbar' rlike '^f.*r$';

    1

    注意:判断一个字符串是否全为数字:

    hive>select 1 from tableName where '123456' rlike '^\d+$';

    1

    hive> select 1 from tableName where '123456aa' rlike '^\d+$';

    11、REGEXP操作: REGEXP

    语法: A REGEXP B
    操作类型: strings
    描述: 功能与RLIKE相同

    hive> select 1 from tableName where 'footbar' REGEXP '^f.*r$';

    1

  • 相关阅读:
    最大子数组问题(分治策略实现)
    Solving the Detached Many-to-Many Problem with the Entity Framework
    Working With Entity Framework Detached Objects
    Attaching detached POCO to EF DbContext
    如何获取qq空间最近访问人列表
    Health Monitoring in ASP.NET 2.0
    problem with displaying the markers on Google maps
    WebMatrix Database.Open… Close() and Dispose()
    Accessing and Updating Data in ASP.NET: Retrieving XML Data with XmlDataSource Control
    Create web setup project that has crystal reports and sql script run manually on client system
  • 原文地址:https://www.cnblogs.com/lojun/p/13246725.html
Copyright © 2011-2022 走看看