我需要在我的spring-boot应用程序中使用JPA Repository创建一个动态查询,以创建从PostgreSQL 返回一些数据的查询
ID Name Status Mode
1 Test1 Processed Mode A
2 Test2 In-Flight Mode B
3 Test3 Processed Mode B
4 Test4 In-Flight Mode A
5 Test5 Processed Mode A
这是表格
Mode Processed In-Flight
Mode A 2 1
Mode B 1 1
以上是所需的退货
我发现下面提到了一个查询
Select mode,
count(*)
filter (where messagelist.routestatus = 'Processed') as processed,
count(*)
filter (where messagelist.routestatus = 'In-Flight') as in_flight,
count(*)
filter (where messagelist.routestatus = 'Failed') as failed
from messagelist
group by mode
order by mode;
需要将此查询更改为动态java查询这个"模式"可能会更改为与用户输入相对应的其他东西,所以我不能使用本机查询需要动态创建查询
试试这样的Jao Query:
@Query("SELECT c.year, COUNT(c.year) FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC")