SELECT
count( commodity.order_base_id ) count,
commodity.activity_code activityCode,
commodity.delivery_type deliveryType,
commodity.STATUS,
commodity.pay_status payStatus
FROM
(
SELECT
t.order_base_id,
t.activity_code,
max(t.order_commodity_id) order_commodity_id,
max(t.STATUS) STATUS,
max(t.pay_status) pay_status,
max(t.delivery_type) delivery_type
FROM
odr_order_commodity t
WHERE
consumer_id = 312 GROUP BY t.activity_code,t.order_base_id ) commodity
GROUP BY
commodity.activity_code,commodity.STATUS,commodity.pay_status,commodity.delivery_type