Using a CASE statement in HQL select

后端 未结 7 609
再見小時候
再見小時候 2020-12-10 01:51

Is there any way to do the following in HQL:

SELECT 
    case when flag = true then SUM(col1) else SUM(col2)
FROM 
    myTable
7条回答
  •  悲哀的现实
    2020-12-10 02:18

    This is an example using a string comparison in the condition:

    SELECT CASE f.type WHEN 'REMOVE'
                       THEN f.previousLocation 
                       ELSE f.currentLocation 
           END 
    FROM FileOperation f
    

提交回复
热议问题