官网:https://www.cloudera.com/documentation/enterprise/latest/topics/impala_math_functions.html

  转载链接1:https://blog.csdn.net/qq_24699959/article/details/79863664

  转载链接2:https://blog.csdn.net/qq_24699959/article/details/80090050

  https://my.oschina.net/weiqingbin/blog/189413#OSC_h2_2

  Impala数据类型:https://blog.csdn.net/yidu_fanchen/article/details/78295499

 

  1、字符串截取substr,从1开始,而不是0;注意一个汉字长度是3

    select brand,substr(brand,1,6) from dw_bill_his limit 10;

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  2、cast函数

    cast(expr AS type), 类型转换函数, 比如将number转成string, 或相反. 

    select cast(length as int) len from dw_bill_his where length != '无' and startdate='2018-09-01' order by cast(length as int);

  3、max,min,avg函数:length字段是字符串类型

    select max(cast(length as int)) len from dw_bill_his where length!='无' and startdate='2018-09-01';

    select min(cast(length as int)) len from dw_bill_his where length!='无' and startdate='2018-09-01';

    select avg(cast(length as int)) len from dw_bill_his where length!='无' and startdate='2018-09-01';

  4、截取数值,四舍五入

    select dround(2.14123,3) result;

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

    select dround(2.14123,2) result;

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

    取整

    select dround(2.14123) result;

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

 

  5、删除所有小数点以后的数或删除N位小数

    select truncate(3.45);

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

    

    select truncate(3.456,1)

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  6、返回表达式列表中的最大值:greatest

     select greatest(5,16,2) as greatest;

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  7、返回表达式列表中的最小值: least

     select least(5,16,2) as least;

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  8、like 模糊查询

    select count(*) from  dw_bill_his where city='北京' and broadcastdate like '2018/03%';

     Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  9、字符串截取,substr(str,startindex,length) startindex从1开始

    select substr('2018-08-20',1,4) year1;

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  10、字符串连接 concat(string a,string b…)

    拼接多个字符串

    --连接hello和world两个字符串
    select concat('hello','world') as concat
    

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  

    concat_ws(string sep,string a,string b…)

    拼接多个字符串,由指定分隔符分割

    --通过'-'连接两个字符串
    select concat_ws('-','hello','world') as concat_ws;

     Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  11、字符串长度 length(string a)

    select length('world') as len;

    Impala 数值函数大全(转载)
    




Impala SQL 语言元素(翻译)

  12、给表增加一列:

    ALTER TABLE name ADD COLUMNS (col_spec[, col_spec ...])

    比如给表dw_bill增加一个float类型的week列

    ALTER TABLE dw_bill ADD COLUMNS(week FLOAT);

  13、删除一列

    ALTER TABLE name DROP [COLUMN] column_name
    比如删除dw_bill的week列表

    ALTER TABLE dw_bill DROP week;

  14、字符串去空格

    去左空格:  select ltrim(' hello ');

    去右空格:  select rtrim(' hello ');

    去左右空格:  select trim(' hello ');

  15、查询某个字段为null的记录条数

    select count(1) from dw_bill where brand is  null;

    不为null的记录条数

    select count(1) from dw_bill where brand is  not null;

 

 

 

相关文章:

  • 2021-09-03
  • 2021-10-16
  • 2022-03-01
  • 2021-05-31
  • 2021-06-12
  • 2021-10-03
  • 2021-09-23
猜你喜欢
  • 2022-03-09
  • 2021-08-20
  • 2022-01-12
  • 2022-02-19
  • 2021-10-24
  • 2021-12-13
  • 2021-06-28
相关资源
相似解决方案