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;

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

时间: 2024-10-06 10:31:45

The expression after ELSE should have the same type as those after THEN: "bigint" is expected but "i的相关文章

ORACLE存储过程如何迁移到HIVE?

在将ORACLE存储过程迁移到HIVE平台时,不可避免地会遇到各种问题. ORACLE与HIVE都使用SQL语句,但是语法和特性不尽相同,本文简述了几个迁移时需要注意的地方. 一.INSERT语句 ORACLE: EXECUTE IMMEDIATE 'TRUNCATE TABLE TABLE_A'; INSERT /*+APPEND*/ INTO A NOLOGGING ( COL_1, COL_2, COL_3, ) 迁移至HIVE语句为: INSERT OVERWRITE TABLE TAB

Expression基础体验

using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace Unit { class T { public void Test() { Console.WriteLine("Test Cl

Expression 表达式树学习整理

整理了一下表达式树的一些东西,入门足够了 先从ConstantExpression 开始一步一步的来吧  它表示具有常量值的表达式 我们选建一个控制台应用程序 ConstantExpression _constExp = Expression.Constant("aaa",typeof(string));//一个常量 //Console.Writeline("aaa"); MethodCallExpression _methodCallexp=Expression.

Expression Trees学习记录

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Windows.Forms; using System.Threading; namespace Express

委托、匿名委托、Lambda 表达式、Expression表达式树之刨根问底

本篇不是对标题所述之概念的入门文章,重点在阐述它们的异同点和应用场景.各位看官,这里就不啰嗦了,直接上代码. 首先定义一个泛型委托类型,如下: public delegate T Function<T>(T a, T b); 实现泛型委托的主体代码,并调用: public static string Add(string a, string b) { return string.Format("{0} #### {1}",a,b); } //实名委托方式 Function&

Expression&lt;Func&lt;TObject, bool&gt;&gt;与Func&lt;TObject, bool&gt;的区别

Func<TObject, bool>是委托(delegate) Expression<Func<TObject, bool>>是表达式 Expression编译后就会变成delegate,才能运行.比如 Expression<Func<int, bool>> ex = x=>x < 100; Func<int, bool> func = ex.Compile(); 然后你就可以调用func: func(5) //-返回

Expression Trees (C# and Visual Basic)

https://msdn.microsoft.com/en-us/library/bb397951.aspx Expression trees represent code in a tree-like data structure, where each node is an expression, for example, a method call or a binary operation such as x < y. You can compile and run code repre

Reflection和Expression Tree解析泛型集合快速定制特殊格式的Json

很多项目都会用到Json,而且大部分的Json都是格式固定,功能强大,转换简单等,标准的key,value集合字符串:直接JsonConvert.SerializeObject(List<T>)就可以搞定了,但凡事并非千篇一律,比如有的时候我们需要的Json可能只需要value,不需要key,并且前后可能还需要辅助信息等等,那该怎么办呢?我所能想到的可能有两种方案,1.自定义跟所需json格式一样的数据结构model,然后用JsonConvert.SerializeObject(model)直

Linq to Sql : 动态构造Expression进行动态查询

原文:Linq to Sql : 动态构造Expression进行动态查询 前一篇在介绍动态查询时,提到一个问题:如何根据用户的输入条件,动态构造这个过滤条件表达式呢?Expression<Func<ProductExt, bool>> predicate t => t.ProductName.Contains("che") && t.UnitPrice >= 22; 理想情况下,我希望可以像下面这样来构造predicate,这样,我