[英]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.