php - How to merge and sum up certain values of items that have the same ID value
one text
Solution:
SELECT name,
SUM(quantity * pack_value) AS quantity,
1 AS pack_value,
order_id
FROM order_items
GROUP BY name,
order_id;
Merge another tables to this code using it as subquery, or add them into FROM clause (adjusting its output list and grouping expression) if needed.
Source