$result_kazpost = DB::select('SELECT SUM(orders.delivery) AS kazpost
FROM orders
JOIN baskets ON orders.basket_id=baskets.id
WHERE baskets.purchase_status = 3 AND orders.deleted_at IS NULL
AND orders.delivery = "kazpost"
AND DATE(orders.created_at) >= :start AND DATE(orders.created_at) <= :finish',
["start"=>$request->start,"finish"=>$request->finish]);
$result_courier = DB::select('SELECT SUM(orders.delivery) AS courier
FROM orders
JOIN baskets ON orders.basket_id=baskets.id
WHERE baskets.purchase_status = 3 AND orders.deleted_at IS NULL
AND orders.delivery = "courier"
AND DATE(orders.created_at) >= :start AND DATE(orders.created_at) <= :finish',
["start"=>$request->start,"finish"=>$request->finish]);
$result_pickup = DB::select('SELECT SUM(orders.delivery) AS pickup
FROM orders
JOIN baskets ON orders.basket_id=baskets.id
WHERE baskets.purchase_status = 3 AND orders.deleted_at IS NULL
AND orders.delivery = "pickup"
AND DATE(orders.created_at) >= :start AND DATE(orders.created_at) <= :finish',
["start"=>$request->start,"finish"=>$request->finish]);
DATE(orders.created_at) >= :start
SELECT orders.delivery, SUM(orders.delivery) AS summ
FROM orders
JOIN baskets ON orders.basket_id=baskets.id
WHERE baskets.purchase_status = 3 AND orders.deleted_at IS NULL
AND orders.created_at >= :start AND orders.created_at <= (:finish + interval 1 day)
GROUP BY orders.delivery
SELECT SUM(if(orders.delivery = "kazpost", orders.delivery,0)) AS kazpost,
SUM(if(orders.delivery = "courier", orders.delivery,0)) AS courier,
SUM(if(orders.delivery = "pickup", orders.delivery,0)) AS pickup
FROM orders
JOIN baskets ON orders.basket_id=baskets.id
WHERE baskets.purchase_status = 3 AND orders.deleted_at IS NULL
AND orders.created_at >= :start AND orders.created_at <= (:finish + interval 1 day)