感激之礼sparksql字段类型转换
1、spark sql 计算时,⼀定要注意精度的问题,⼀般像⾦额之类的值,要先转换为double或者 decimal来进⾏计算了。⼀、sql的⽅式:
lect
炸薯片
shop_id,order_id,sum(cast(deal_price as decimal(15,2))) deal_price,sum(cast(total_price as decimal(15,2))) total_price from aaa
医院举报电话
where stat_day='20190617'
and cid1 not in (293,-1)
and cid2 not in (422,421,427,525,446)
工资所得税and substr(pay_time,1,10)>='2019-06-01'
and substr(pay_time,1,10)<='2019-06-17'
家常可乐鸡翅group by shop_id,order_id
人人bt
⼆、df的⽅式:读后感300字
c_tran_df.withColumn("l_picked_amt", c_tran_df("l_special_amt").cast(DecimalType(15,4)))
decimal(15,2)
2 表⽰⼩数部分的位数,如果插⼊的值,未指定⼩数部分或者⼩数部分不⾜两位,则会⾃动补到2为⼩数。
15 表⽰整数部分加⼩数部分的总长度。
>读书明理