UNION ALL的用法:
如果使用了order by 进行排序 一定要加上括号
(SELECT
csc.id,
csc.member_id,
csc.menu_id,
SUM(csc.num) num,
cmi.original_price,
cmi.price price,
cmi.picture menu_picture,
cmi.NAME menu_name,
cmi.is_need_weigh,
cmi.unit bookQueueId,
csc.menu_spec_id,
csc.flavour,
csc.menu_pack_type,
cmi.abbreviated_picture abbreviated_picture,
(SELECT name
FROM cat_menu_library_spec
WHERE id IN (
SELECT menu_spec_id
FROM shopping_cart s
WHERE
s.shop_id = #{shopId}
AND s.member_id = #{memberId}
AND s.num > 0
AND s.STATUS = 1
)
) created_by
FROM
shopping_cart csc
INNER JOIN cat_menu cmi ON csc.menu_id = cmi.id
WHERE
csc.shop_id = #{shopId}
AND csc.member_id = #{memberId}
AND csc.num > 0
AND csc.STATUS = 1
AND csc.menu_pack_type = 0
AND csc.source_type = 0
GROUP BY
csc.menu_id,
csc.menu_spec_id,
csc.flavour
ORDER BY
csc.last_updated_date
)
UNION ALL
(SELECT
cc.id,
cc.member_id,
cc.menu_id,
SUM(cc.num) num,
cp.price original_price,
cp.price price,
cp.cover_img menu_picture,
cp.name menu_name,
false isNeedWeigh,
0 bookQueueId,
cc.menu_spec_id,
cc.flavour,
cc.menu_pack_type,
cp.abbreviated_cover_img abbreviated_picture,
'份' created_by
FROM
shopping_cart cc
INNER JOIN cat_pack cp ON cc.menu_id = cp.id
WHERE
cc.shop_id = #{shopId}
AND cc.member_id = #{memberId}
AND cc.num > 0
AND cc.STATUS = 1
AND cc.menu_pack_type != 0
AND cc.source_type = 0
GROUP BY
cc.menu_id,
cc.menu_spec_id,
cc.flavour
ORDER BY
cc.last_updated_date
)