mysql过程结果中存在重复行

xqkwcwgp  于 2021-06-15  发布在  Mysql
关注(0)|答案(0)|浏览(167)

mysql过程返回多个表的结果。问题是,它经常返回重复的行。
甚至 Distinct 没用。
以下是示例:
重复的行
问题是,我做错了什么?

CREATE DEFINER=`root`@`localhost` PROCEDURE `GetOrderItems`( last_order_id INT )
BEGIN
    SELECT
        DISTINCT items.order_item_id AS `id`,
        items.order_id AS `order_id`,
        items.order_item_name AS `name`,
        items.order_item_type AS `type`,
        qty.meta_value AS `qty`,
        line_total.meta_value AS `line_total`,
        item_note.meta_value AS `line_note`,
        item_options.text AS `options` 
    FROM
        wp_woocommerce_order_items AS items
        LEFT JOIN wp_woocommerce_order_itemmeta AS qty ON items.order_item_id = qty.order_item_id 
        AND `qty`.meta_key = "_qty"
        LEFT JOIN wp_woocommerce_order_itemmeta AS line_total ON items.order_item_id = line_total.order_item_id 
        AND `line_total`.meta_key = "_line_total"
        LEFT JOIN wp_woocommerce_order_itemmeta AS item_note ON items.order_item_id = item_note.order_item_id 
        AND `item_note`.meta_key = "  "
        LEFT JOIN (
        SELECT
            `order_item_id`,
            GROUP_CONCAT( `meta_value` SEPARATOR '; ' ) AS `text` 
        FROM
            wp_woocommerce_order_itemmeta 
        WHERE
            LOWER( `meta_key` ) LIKE '%option%' 
            OR LOWER( `meta_key` ) LIKE '%size%' 
            OR LOWER( `meta_key` ) LIKE '%add extra%' 
        GROUP BY
            `meta_key`,
            `order_item_id` 
        ) item_options ON items.order_item_id = item_options.order_item_id 
    WHERE
        items.order_id > last_order_id;

END

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题