I don't believe HQL supports if()
as a function. The following should work in both databases:
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
Question
guys thanks for your time and help i have this 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
i try this on 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
i get Error:
java.lang.NullPointerException
at org.hibernate.dialect.Dialect$3.getReturnType(Dialect.java:102)
what i have to check?
Solution
I don't believe HQL supports if()
as a function. The following should work in both databases:
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