gpt4 book ai didi

java - 可以在 hibernate 状态 "and"中使用 "case when...then...else...end"吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:25:39 25 4
gpt4 key购买 nike

我有以下查询:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com