Hibernate标准总和

时间:2014-02-15 20:40:29

标签: mysql sql hql

伙计们感谢您的时间并帮助我拥有这个Mysql SQL

SELECT
IFNULL(SUM(IF((P_P LIKE 'P%'), 1, 0)), 0) AS numIn,
IFNULL(SUM(IF((P_A LIKE 'A%'), 1, 0)), 0) AS numOut
FROM PA_DATE

我在HQL上尝试这个

SELECT
COALESCE(SUM(IF((P_P LIKE 'P%'), 1, 0)), 0) AS numIn,
COALESCE(SUM(IF((P_A LIKE 'A%'), 1, 0)), 0) AS numOut
FROM PaDate

我收到错误:

    java.lang.NullPointerException
at org.hibernate.dialect.Dialect$3.getReturnType(Dialect.java:102)

我必须检查什么?

1 个答案:

答案 0 :(得分:1)

我不相信HQL支持if()作为函数。以下内容应适用于两个数据库:

SELECT SUM(case when P_P LIKE 'P%' then 1 else 0 end) AS numIn,
       SUM(case when P_A LIKE 'A%' then 1 else 0 end) AS numOut
FROM PaDate