hello i need help i was try but give up
i have table shipping
id | order_id | supplier_id | shipping_cost |
---|---|---|---|
1 | 37575000001 | 2 | 20000 |
2 | 37575000001 | 2 | 40000 |
3 | 37575000001 | 10 | 20000 |
4 | 37575000001 | 10 | 30000 |
i want to calculate height shipping_cost with same supplier_id from the table is 40000 and 30000 total_shipping_cost is 70000
i was try with query
<?php
$query = "SELECT shipping_cost FROM shipping where order_id='37575000001' group by supplier_id order by shipping_cost desc";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($result))
{
$shipping_cost=$row['shipping_cost'];
$total_shipping_cost=$total_shipping_cost+$shipping_cost;
}
echo $total_shipping_cost;
?>
but the result is 40000
please help
SELECT DISTINCT SUM(MAX(shipping_cost)) OVER () AS total_shipping_cost
FROM shipping
GROUP BY supplier_id;