[英]Is there a way count(if) query in QueryDsl?
我想要像那个查询那样的结果。
SELECT
book_id,
COUNT(member_id),
COUNT(if(returned = 1, 1, null))
...
QueryDSL 中有 case-when 查询,但这并不是我想要的。
我找不到任何使用 COUNT IF 查询的方法。
所以我想知道有没有什么方法可以使用在 querydsl 中使用 COUNT IF function 的 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);
或者我应该使用 CaseBuilder() 吗?
new CaseBuilder()
.when(bookRental.returned.eq(true))
.then(bookRental.memberId.count(1))
.otherwise(0)
bookRental.memberId.eq('test').count().as("bookRentalCount")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.