我有以下查询:
select myentity from TEST as test
left join test.org.parent as parentOrg
left join test.clientRequest as clientReq
where test.customId = 1 and (test.dstatus = 1 or test.cm = true)
order by (case when test.request != '' then test.request else clientReq.name end) asc;
它工作正常。但我不仅需要 clientReq.name
,还需要 clientReq.surname
。在这个case when...then...else...end
中是否可以合并这两列?
类似于:
order by (case when test.request != '' then test.request else (clientReq.name and clientReq.surname) end) asc;
这个抛出异常:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node
最佳答案
既然你在排序,我想你的意思是连接名字和姓氏:
order by (case when test.request != '' then test.request else concat(clientReq.name,clientReq.surname) end) asc;
参见 HQL Query Expressions在文档中获取更多详细信息。
关于java - 可以在 hibernate 状态 "and"中使用 "case when...then...else...end"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21882466/