Prestashop 1.6xx 从数据库中导出所有带有折扣产品和折扣代码的订单
Prestashop 1.6xx Export all the orders with discounted products and discount code from database
我需要在 CSV 文件中导出所有带有折扣代码的订单和打折产品。
我已经完成了这个查询:
SELECT * FROM `ps_orders` WHERE `date_add` BETWEEN '2017-01-01
00:00:00' and '2017-03-31 23:59:59' AND `total_discounts` > 0 AND
`current_state` LIKE 4
现在我有一个带有折扣代码的订单列表,但我还需要带有折扣产品的订单。
我该怎么办?
谢谢,祝你有个愉快的一天。
您可以对订单详细信息使用 Left Join:
SELECT *
FROM `ps_orders` o
LEFT JOIN `ps_order_detail` od
ON o.`id_order` = od.`id_order`
WHERE o.`date_add` BETWEEN '2017-01-01 00:00:00' and '2017-03-31 23:59:59'
AND (o.`total_discounts` > 0 OR od.`reduction_percent` > 0 OR od.`reduction_amount` > 0)
AND o.`current_state` LIKE 4
如果需要,您可以选择所需的字段,而不是 *。
如果您只需要来自订单的数据,请使用:
SELECT o.*
FROM `ps_orders` o
LEFT JOIN `ps_order_detail` od
ON o.`id_order` = od.`id_order`
WHERE o.`date_add` BETWEEN '2017-01-01 00:00:00' and '2017-03-31 23:59:59'
AND (o.`total_discounts` > 0 OR od.`reduction_percent` > 0 OR od.`reduction_amount` > 0)
AND o.`current_state` LIKE 4
GROUP BY o.`id_order`
我需要在 CSV 文件中导出所有带有折扣代码的订单和打折产品。
我已经完成了这个查询:
SELECT * FROM `ps_orders` WHERE `date_add` BETWEEN '2017-01-01
00:00:00' and '2017-03-31 23:59:59' AND `total_discounts` > 0 AND
`current_state` LIKE 4
现在我有一个带有折扣代码的订单列表,但我还需要带有折扣产品的订单。
我该怎么办? 谢谢,祝你有个愉快的一天。
您可以对订单详细信息使用 Left Join:
SELECT *
FROM `ps_orders` o
LEFT JOIN `ps_order_detail` od
ON o.`id_order` = od.`id_order`
WHERE o.`date_add` BETWEEN '2017-01-01 00:00:00' and '2017-03-31 23:59:59'
AND (o.`total_discounts` > 0 OR od.`reduction_percent` > 0 OR od.`reduction_amount` > 0)
AND o.`current_state` LIKE 4
如果需要,您可以选择所需的字段,而不是 *。 如果您只需要来自订单的数据,请使用:
SELECT o.*
FROM `ps_orders` o
LEFT JOIN `ps_order_detail` od
ON o.`id_order` = od.`id_order`
WHERE o.`date_add` BETWEEN '2017-01-01 00:00:00' and '2017-03-31 23:59:59'
AND (o.`total_discounts` > 0 OR od.`reduction_percent` > 0 OR od.`reduction_amount` > 0)
AND o.`current_state` LIKE 4
GROUP BY o.`id_order`