Using a CASE statement in HQL select

后端 未结 7 613
再見小時候
再見小時候 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条回答
  •  猫巷女王i
    2020-12-10 02:32

    Below you can find a working query (hibernate on postgresql) that uses 2 case statements to replace a boolean value with the corresponding textual representation.

    SELECT CASE ps.open WHEN true THEN 'OPEN' else 'CLOSED' END, CASE ps.full WHEN true THEN 'FULL' else 'FREE' END, ps.availableCapacity FROM ParkingState as ps

提交回复
热议问题