Bir filtre kısmı ile uğraşıyorum fakat bu kodum Sequal ACE de query kısmında çalışıp 3 kayıt getirirken filtre kısmında kullanmak için laravel koduma yazdım da çalışmıyor
->query(function (Builder $query, array $data): Builder {
$type = $data['type_timezone'] ?? null;
if ($type === "Yıllık") {
$query->selectRaw('
MIN(id) as id,
YEAR(date_of_sales) as year,
COUNT(*) as sales_count,
SUM(order_total_amount) as total_amount,
ANY_VALUE(date_of_sales) as date_of_sales,
GROUP_CONCAT(id) as order_ids
')
->whereNull('deleted_at')
->whereNotNull('date_of_sales')
->groupBy(DB::raw('YEAR(date_of_sales)'))
->orderBy(DB::raw('YEAR(date_of_sales)'), 'desc');
}
return $query;
}),
SQL Kodum
SELECT
MIN(id) as id,
YEAR(date_of_sales) as year,
COUNT(*) as sales_count,
SUM(order_total_amount) as total_amount,
ANY_VALUE(date_of_sales) as date_of_sales,
GROUP_CONCAT(id) as order_ids
FROM orders
WHERE
deleted_at IS NULL
AND date_of_sales IS NOT NULL
AND orders.deleted_at IS NULL
GROUP BY YEAR(date_of_sales)
ORDER BY YEAR(date_of_sales) ASC;