【问题标题】:Order By with select query in hibernate在休眠中使用选择查询排序
【发布时间】:2021-12-24 21:01:20
【问题描述】:

我有这个 SQL 服务器查询:

SELECT * from DOCUMENTS 
where isdeleted = 1 and deletedBy = 1
ORDER BY (select USERS.FIRSTNAME from USERS where DOCUMENTS.CreatedBy = USERS.DKEY) asc;

它在 SQL Server 中运行良好。但是我想写的是HQL,我尝试了很多方法但都不起作用:

hql = "from DOCUMENTS d where d.isdeleted = true and d.deletedBy = true
ORDER BY (select ue.firstname from Users ue where d.createdBy = ue.dkey) asc";

【问题讨论】:

    标签: sql sql-server hibernate hql


    【解决方案1】:

    如果您的表格设计为DocumentsUsers 之间的关系,您可以按DOCUMENTS.createdBy.firstname 对其进行排序,如下所示:

    SELECT d 
    FROM DOCUMENTS d 
    WHERE d.isdeleted = true 
    AND d.deletedBy = true
    ORDER BY d.createdBy.firstname ASC
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多