Issue
Is there any way to do the following in HQL:
SELECT
case when flag = true then SUM(col1) else SUM(col2)
FROM
myTable
Solution
I guess you can (href="http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/queryhql.html#queryhql-expressions" rel="noreferrer">3.6, 4.3) [inline edit] ...for where-clauses:
"Simple" case,
case ... when ... then ... else ... end
, and "searched" case,case when ... then ... else ... end
Answered By - Henrik Paul
Answer Checked By - Robin (JavaFixing Admin)