presto字符串转浮点数、整数处理
作者:互联网
1. 相除保留小数位
Presto中两个整数相除会结果为零。当我们相除的两个数都为整数时,比如我想用两个count()结果相除,想保留n为小数
select count(*)*1.00 / count(*) from student;
结果就会自动保留两位小数,想要n位就1.后面n个零
2. 字符串转整数
select cast (bj_score as bigint), bj_score from dcs_input_tab_bj_score
3. 字符串转浮点
select cast (bj_score as double), bj_score from dcs_input_tab_bj_score
4. round(x, d) 保留d位小数,对后面的做四舍五入
select round(976.56374123, 5); --对第5位后的做四舍五入
5. is_nan(x) 判断浮点数是为为空,返回true或者false
select is_nan(976.56374123);
6. rand() 随机生成一个随机浮点数
select rand();
标签:count,presto,浮点数,bj,score,相除,字符串,select 来源: https://blog.csdn.net/zhuchunyan_aijia/article/details/122419042