UNION ALL 用法

UNION ALL 用法UNIONALL的用法:如果使用了orderby进行排序一定要加上括号(SELECTcsc.id,csc.member_id,csc.menu_id,SUM(csc.num)num,cmi.original_price,…


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
        )

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/34377.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注