Impala 数值函数大全(转载)

  官网: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

  Impala SQL 语言元素(翻译)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;

    

  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;

    

    select dround(2.14123,2) result;

    

    取整

    select dround(2.14123) result;

    

 

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

    select truncate(3.45);

    

    

    select truncate(3.456,1)

    

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

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

    

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

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

    

  8、like 模糊查询

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

     

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

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

    

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

    拼接多个字符串

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

    

  

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

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

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

     

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

    select length('world') as len;

    

  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;

 

 

 
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值