将带有子查询连接的 SQL 查询转换为 HQL
我没有设法在 HQL 中转换这种查询:
SELECT table.*
FROM Table table, (SELECT kind, max(date) as maxdate FROM Table GROUP BY kind) subrequest
WHERE table.kind = subrequest.kind AND date = subrequest.maxdate
表是一个大表,包含很多属性,我想选择每种类型的最后一个条目。 通过在 FROM 部分进行子查询,我节省了大量时间。有什么想法吗?
原始查询是:
SELECT table.*
FROM Table table
WHERE table.date = (SELECT max(date) FROM Table WHERE kind = table.kind)
在 HQL 中转换很容易,但速度较慢。
I did not manage to convert this kind of query in HQL :
SELECT table.*
FROM Table table, (SELECT kind, max(date) as maxdate FROM Table GROUP BY kind) subrequest
WHERE table.kind = subrequest.kind AND date = subrequest.maxdate
Table is a big table and contains many attributes, I want to select the last entries of each kind.
By doing the sub query in FROM part, I save a lot of time. Any idea ?
Original query was :
SELECT table.*
FROM Table table
WHERE table.date = (SELECT max(date) FROM Table WHERE kind = table.kind)
It's easy to convert in HQL but slower.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论