У меня есть собственный запрос:
@Query( value = "select to_char(o.earliest_delivery_time at time zone 'UTC', 'Mon YYYY') as month, " +
" count(o.id) as orderQuantity, " +
" sum(lp.net_qty) as gallonQuantity " +
" from orders o " +
" left join lifts l on o.id = l.order_id " +
" left join liftproducts lp on l.id = lp.lift_id " +
" where earliest_delivery_time>= :startReportDate " +
" AND o.status in :statuses" +
" AND (o.bill_to_id IN (:userCompany)" +
" OR o.carrier_id in (:userCompany) OR o.retailer_id in (:userCompany)" +
" OR o.wholesaler_id in (:userCompany) OR o.requestor_id in (:userCompany)) " +
" group by to_char(o.earliest_delivery_time at time zone 'UTC', 'Mon YYYY')", nativeQuery = true)
List<OrdersByTimeDashboardDto> getOrdersByTime(@Param("startReportDate") Instant startReportDate,
@Param("userCompany") Long userCompany,
@Param("statuses") Collection<String> statuses,
);
И он работает нормально, но теперь я хочу передать часовой пояс в качестве параметра, поэтому:
@Query( value = "select to_char(o.earliest_delivery_time at time zone :timezone, 'Mon YYYY') as month, " +
" count(o.id) as orderQuantity, " +
" sum(lp.net_qty) as gallonQuantity " +
" from orders o " +
" left join lifts l on o.id = l.order_id " +
" left join liftproducts lp on l.id = lp.lift_id " +
" where earliest_delivery_time>= :startReportDate " +
" AND o.status in :statuses" +
" AND (o.bill_to_id IN (:userCompany)" +
" OR o.carrier_id in (:userCompany) OR o.retailer_id in (:userCompany)" +
" OR o.wholesaler_id in (:userCompany) OR o.requestor_id in (:userCompany)) " +
" group by to_char(o.earliest_delivery_time at time zone :timezone, 'Mon YYYY')", nativeQuery = true)
List<OrdersByTimeDashboardDto> getOrdersByTime(@Param("startReportDate") Instant startReportDate,
@Param("userCompany") Long userCompany,
@Param("statuses") Collection<String> statuses,
@Param("timezone") String timezone
);
например, часовой пояс может быть: String timezone = "UTC";
И после этих изменений я получил ошибку:
ОШИБКА: столбец «o.earliest_delivery_time» должен появляться в предложении GROUP BY или использоваться в статистической функции
Я пробовал много решений, но у меня ничего не работает.