简体   繁体   English

使用HQL查找最大ID

[英]Finding the max id using HQL

So I have a HQL Query like so: 所以我有一个像这样的HQL查询:

String query = "from records where lastUpdateTime >=:startDate " +
               "AND lastUpdateTime < :endDate";

I need to change it so that I only retreive the latest version of a record between the two dates. 我需要更改它,以便我只能在两个日期之间检索最新版本的记录。

So I have: 所以我有:

ID | VERSION | other records | LASTUPDATETIME

I need to use a max on the VERSION but my knowledge of HQL is letting me down. 我需要在VERSION上使用max,但是我对HQL的了解让我感到失望。

You might need something like that: 你可能需要这样的东西:

String query = "from records r where r.lastUpdateTime >=:startDate " +
               "AND r.lastUpdateTime < :endDate AND r.version = (select max(rec.version) from record rec where rec.id = r.id)";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM