DATEDIFF로 항목 주문

Oct 27 2020

두 날짜 필드의 차이로 항목 쿼리의 결과를 정렬하려고하는데 작동하지 않는 것 같습니다.

내 질문은 다음과 같습니다.

{% set todaysStreamsParams = {
  section : 'films',
  orderBy : "DATEDIFF(`screeningDateFirst`, `screeningDateLast`) DESC",
  limit   : 5,
} %}

{% set todaysStreams = craft.entries(todaysStreamsParams).all() %}

하지만 다음 데이터베이스 예외가 발생합니다.

Unknown column 'screeningDateFirst' in 'order clause.

팁이 있습니까?

답변

1 DocumentServices Oct 27 2020 at 08:43

좀 더 자세히 살펴보면 더 복잡한 주문 쿼리를 완전히 정교화해야하는 것 같습니다. 작동하도록 다음과 같이 조정했습니다.

orderBy : "DATEDIFF(`content`.`field_screeningDateFirst`, `content`.`field_screeningDateLast`) DESC",