where
m.email = ?1 and m.name = ?2
SELECT CASE WHEN COUNT(*) > 0 THEN TRUE ELSE FALSE END
FROM like
WHERE user_id = :userId AND post_id = :postId;
findByCreatedAtAfterAndPriceLessThanOrderByPriceDescItemIdDesc
LessThanEqual <=
is와 like의 차이
ignoreCase : 대소문자 구분없이
벌크성 쿼리
파라미터로 인터페이스를 받은 경우
-> 사용시 객체를 구현해야한다.
@Override
public List<Item> findNewItemsOrderBy(Long lastIdx, Long lastItemId, ItemSortType sortType,
Pageable pageable)
OrderSpecifier orderSpecifier = createOrderSpecifier(sortType);
private OrderSpecifier createOrderSpecifier(ItemSortType sortType) {
return switch (sortType) {
case NEW -> new OrderSpecifier<>(Order.DESC, item.itemId);
case HIGHEST_AMOUNT -> new OrderSpecifier<>(Order.DESC, item.price);
case LOWEST_AMOUNT -> new OrderSpecifier<>(Order.ASC, item.price);
case DISCOUNT -> new OrderSpecifier<>(Order.DESC, item.discount);
default -> new OrderSpecifier<>(Order.DESC, item.orderItems.any().quantity.sum());
};
}
// 참조는 기준이 될 수 있다.
//
Predicate predicate = item.createdAt.after(LocalDateTime.now().minus(NEW_PRODUCT_REFERENCE_TIME, ChronoUnit.WEEKS));
private Predicate getHavingCondition(Long lastIdx, Long lastItemId, ItemSortType sortType) {
return switch (sortType) {
case NEW -> item.itemId.lt(lastIdx);
case HIGHEST_AMOUNT -> item.price.lt(lastIdx)
.or(item.price.eq(lastIdx.intValue()).and(item.itemId.gt(lastItemId)));
case LOWEST_AMOUNT -> item.price.gt(lastIdx)
.or(item.price.eq(lastIdx.intValue()).and(item.itemId.gt(lastItemId)));
case DISCOUNT -> item.discount.lt(lastIdx)
.or(item.discount.eq(lastIdx.intValue()).and(item.itemId.gt(lastItemId)));
default -> JPAExpressions.select(orderItem.quantity.longValue().sum().coalesce(0L))
.from(orderItem)
.where(orderItem.item.eq(item))
.lt(lastIdx);
};
}
| 함수 | 설명 |
|---|---|
| lt | less than |
| gt | greater than |
| or | |
| eq | |
| and | |
| any | |
| sum |
ONLY_FULL_GROUP_BY 모드: MySQL의 ONLY_FULL_GROUP_BY 모드가 해제되어 있는 경우에는 GROUP BY 절에 있는 필드가 SELECT 목록에 포함되어 있지 않아도 쿼리를 실행할 수 있습니다.