【问题标题】:Object query language | execute both "order by" and "where" clauses对象查询语言 |执行“order by”和“where”子句
【发布时间】:2010-07-05 08:31:20
【问题描述】:

如何使用对象查询语言根据 where 子句和 order by 子句整理一些数据这是我正在使用的查询,但我不确定它是否有效。

SELECT user from user.User as user WHERE user.status=1 order by user.username

谢谢。

【问题讨论】:

    标签: java hibernate orm hql


    【解决方案1】:

    您的查询看起来不错。来自参考文档:

    14.11. The order by clause

    查询返回的列表可以是 由返回的任何属性订购 类或组件:

    from DomesticCat cat
    order by cat.name asc, cat.weight desc, cat.birthdate
    

    可选的 asc 或 desc 表示 升序或降序 分别。

    【讨论】:

      【解决方案2】:

      我觉得应该写得更像

      SELECT `users`.* FROM `users` WHERE `users`.`status` = 1 ORDER BY `users`.`username`
      

      这假设您有一个名为 users 的表,并且想要选择 status1 的所有行,按用户名列排序。

      【讨论】:

        猜你喜欢
        • 2010-10-24
        • 1970-01-01
        • 2012-03-16
        • 1970-01-01
        • 1970-01-01
        • 2021-09-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多