msyql通过临时表提高效率方案查询订单表并且根据商品子表汇总商品数量
CREATE TEMPORARY TABLE temp_client_order_info AS (
SELECT *
FROM client_order_info
WHERE merchantkeynum = '70CE0924B224E0964C209B7F560F7054'
);
-- 创建子表临时表
CREATE TEMPORARY TABLE temp_client_order_orderdetail AS (
SELECT *
FROM client_order_orderdetail
WHERE merchantkeynum = '70CE0924B224E0964C209B7F560F7054'
);
-- 最后,通过临时表查询结果
SELECT cio.order_id, SUM(cood.number) AS total_quantity
FROM temp_client_order_info AS cio
LEFT JOIN temp_client_order_orderdetail cood ON cio.order_id = cood.order_id
GROUP BY cio.order_id;
版权声明:若无特殊注明,本文皆为《菜鸟站长》原创,转载请保留文章出处。
本文链接:msyql通过临时表提高效率方案查询订单表并且根据商品子表汇总商品数量 - https://wziyi.net/?post=433