我正在使用DatabaseClient执行我的sql查询,但看不到如何进行分组:
databaseClient.select()
.from( myClass.class )
.matching( where( "row_1" ).is( "value_1" ) )
//group by row_2 ...
.orderBy( Sort.Order.desc( "row_3" ) )
.page( pageable )
.fetch()
.all();
答案 0 :(得分:0)
直接使用sql的解决方法。
public Flux<Map<Object, Object>> countByStatus() {
return this.databaseClient
.sql("SELECT count(*) as cnt, status FROM posts group by status")
.map((row, rowMetadata) -> {
Long cnt = row.get("cnt", Long.class);
Post.Status s = row.get("status", Post.Status.class);
return Map.<Object, Object>of("cnt", cnt, "status", s);
})
.all();
}