简体   繁体   English

如何在 Java Spring 引导 JPA SQL 查询中使用 SQL - ROW_NUMBER() function?

[英]How to use SQL - ROW_NUMBER() function in Java Spring Boot JPA SQL-Query?

I want to write a query in Java Spring Boot persistence API, the SQL query would look like this:我想在 Java Spring Boot persistence API 中编写查询,SQL 查询如下所示:

select useruuid, score, timeneeded, ROW_NUMBER() OVER 
(order by score desc, timeneeded) AS new_column 
from scores order by score desc, timeneeded;

I know how to write the Basic JPA Queries, but I haven't find the function row_number, is there any?我知道如何编写基本 JPA 查询,但我没有找到 function row_number,有吗?

My question would be- How to correctly use the row_number function in spring boot to set an Index over a sorted result list?我的问题是 - 如何在 spring 引导中正确使用row_number function 来设置排序结果列表的索引?

You can do it directly in JPQL when you start using Hibernate 6.当您开始使用 Hibernate 6 时,您可以直接在 JPQL 中执行此操作。

=> Hibernate 6 with JPQL Window functions => Hibernate 6 具有 JPQL Window 功能

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

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