Запрос ниже работает, но он отлично показывает две разные суммы разных ордеров, как я сделал GROUP BY ORDER_ID
как (1000, 2000)
.
Но я хочу это (1000, 2000)
как (3000). Если в неделю 2 заказа, то 1 имеет процентную скидку, а один - без скидки, и каждый заказ имеет разную стоимость доставки.
Каждый заказ имеет различный процент скидки и разную стоимость доставки.
Вот почему я сделал group by order_id
в своем запросе, и если я удаляю group by order_id
, это даст мне другую общую сумму. Но с group by order_id
он показывает правильное количество заказов на текущую неделю, месяц или год.
Пожалуйста, помогите в этом отношении.
Ниже мой вопрос, что я пытаюсь сделать.
$totalX = "select sum(price) as price, coupon, city, delivery_type, order_id
from orders where date between '2018-09-12' and '2018-09-13' group by order_id";
$totalXx = $dba2->query($totalX);
while ($total = $totalXx->fetch_assoc()) {
$couponX = "select coupon, price, percent from couponsAll where id = '".$total['coupon']."'";
$couponXx = $dba->query($couponX);
$coupon = $couponXx->fetch_assoc();
$areaBX = "select * from countries_citiesALL where id = '".$total['city']."' ";
$areaBXx = $dba->query($areaBX);
$areaBXxx = $areaBXx->fetch_assoc();
$area6X = "select * from delivery_typeALL where area = '".$total['city']."' and id = '".$total['delivery_type']."'";
$area6Xx = $dba->query($area6X);
$area6xXx = $area6Xx->fetch_assoc();
$dchargezQ = $area6xXx['price'];
if ($coupon['price'] >= 1 && $coupon['percent'] < 1) {
/// this condition is if price based discount
$priceAcoup = $total['price'] - $coupon['price'];
$gtotalx = $priceAcoup + $areaBXxx['price'] + $dchargezQ;
$gtotal = number_format($gtotalx, 3);
echo '<font color="black" style=""><b>'.$gtotal.'</b></font>';
} else {
if ($coupon['price'] < 1 && $coupon['percent'] >= 1) {
/// this condition is if percentage based discount
$priceAcoup = $total['price'] - (($total['price'] * $coupon['percent']) / 100);
$gtotalx = $priceAcoup + $areaBXxx['price'] + $dchargezQ;
$gtotal = number_format($gtotalx, 3);
echo '<font color="black" style=""><b>'.$gtotal.'</b></font>';
} else {
/// this condition is if there is no percentage or price based discount
$gtotalx = $total['price'] + $areaBXxx['price'] + $dchargezQ;
$gtotal = number_format($gtotalx, 3);
echo '<font color="black" style=""><b>'.$gtotal.'</b></font>';
}
}
}