The expression after ELSE should have the same type as those after THEN: "bigint" is expected but "i

hive中执行sql语句:
select pc.category_id, 
sum(case when t.so_month between 3 and 5 then t.order_item_num else 0 end) as spring, 
sum(case when t.so_month between 6 and 8 then t.order_item_num else 0 end) as summer, 
sum(case when t.so_month between 9 and 11 then t.order_item_num else 0 end) as autumn, 
sum(case when t.so_month=12 or t.so_month<=2 then t.order_item_num else 0 end) as winnter 
from product_category pc join (select si.product_id, si.order_item_num, month(si.order_create_time) as so_month from so_item si where si.ds between '2013-05-01' and '2014-04-30' and si.is_gift=0) t on pc.product_id=t.product_id 
group by pc.category_id;
其中t.order_item_num是bigint类型

执行sql,提示 错误
“The expression after ELSE should have the same type as those after THEN: "bigint" is expected but "int" is found”

解决办法:
把else后面的0改为0L即可!
select pc.category_id, 
sum(case when t.so_month between 3 and 5 then t.order_item_num else 0L end) as spring, 
sum(case when t.so_month between 6 and 8 then t.order_item_num else 0L end) as summer, 
sum(case when t.so_month between 9 and 11 then t.order_item_num else 0L end) as autumn, 
sum(case when t.so_month=12 or t.so_month<=2 then t.order_item_num else 0L end) as winnter 
from product_category pc join (select si.product_id, si.order_item_num, month(si.order_create_time) as so_month from so_item si where si.ds between '2013-05-01' and '2014-04-30' and si.is_gift=0) t on pc.product_id=t.product_id 
group by pc.category_id;
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值