UNION ALL 用法

 
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
        )


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值