Задача: посмотреть сколько денег было потерянно на отмененных заказах: Решение: SELECT t.orders_id,o.date_purchased, t.value , s.orders_status_id, st.orders_status_name , (case s.orders_status_id when 4 then t.value else 0 end) canceled , (case s.orders_status_id when 3 then t.value else 0 end) delivered FROM `orders_total` t, orders o ,orders_status_history s ,orders_status st WHERE t.orders_id=o.orders_id and t.class='ot_total' and s.orders_id=o.orders_id and st.orders_status_id=s.orders_status_id and s.orders_status_history_id=(select max(s1.orders_status_history_id) from orders_status_history s1 where s1.orders_id=o.orders_id group by s1.orders_id) order by o.date_purchased desc; Результат: Читать далее OS-commerce: анализ заказов и их выполнений