取最大值并分组

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

posted @ 2020-03-06 11:17  怕黑,可是却恋上了夜  阅读(101)  评论(0编辑  收藏  举报