[英]Is there a way count(if) query in QueryDsl?
I want to result like that query.我想要像那个查询那样的结果。
SELECT
book_id,
COUNT(member_id),
COUNT(if(returned = 1, 1, null))
...
There is case-when query in QueryDSL, But it is not what I want exactly. QueryDSL 中有 case-when 查询,但这并不是我想要的。
I can't find any ways to use COUNT IF query.我找不到任何使用 COUNT IF 查询的方法。
So I wonder is there any ways about using COUNT() query that used COUNT IF function in querydsl.所以我想知道有没有什么方法可以使用在 querydsl 中使用 COUNT IF function 的 COUNT() 查询。
https://www.mysqltutorial.org/mysql-count/ https://www.mysqltutorial.org/mysql-count/
JPQLQuery<?> countDto = getQueryDsl().createQuery()
.select(bookRental.bookId, bookRental.memberId.count(), bookRental.memberId.count(...)
.from(bookRental)
.where(bookId.in(bookIds))
.groupBy(bookRental.bookId);
Or Should I use CaseBuilder()?或者我应该使用 CaseBuilder() 吗?
new CaseBuilder()
.when(bookRental.returned.eq(true))
.then(bookRental.memberId.count(1))
.otherwise(0)
bookRental.memberId.eq('test').count().as("bookRentalCount") bookRental.memberId.eq('test').count().as("bookRentalCount")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.