如何使用 Spring Data JPA 进行不同的计数?我不想使用@Query
注释。等效的 sql 查询将是:
SELECT COUNT(DISTINCT rack) FROM store WHERE id = 10001;
我尝试编写以下查询,但它不起作用:
int countDistinctRackById();
如何使用 Spring Data JPA 进行不同的计数?我不想使用@Query
注释。等效的 sql 查询将是:
SELECT COUNT(DISTINCT rack) FROM store WHERE id = 10001;
我尝试编写以下查询,但它不起作用:
int countDistinctRackById();
这应该工作:
Integer countDistinctRackById(Long id);
我刚刚尝试过,现有的答案都不起作用。
以下查询:
Integer countDistinctRackById(String id);
将呈现如下内容:
select distinct count(table0_.rack) as col_0_0_ from table table0_ where table0_.id=?
由于我目前坚持使用 Spring Boot 1.2.3,如果以后有任何更改,请注意,但是为了实现不同的计数,我必须定义一个自定义查询:
@Query("Select count(distinct rack) from Table t where t.id = ?1")