gpt4 book ai didi

mysql - Magento 直接 SQL 查询基于优惠券的订单?

转载 作者:行者123 更新时间:2023-11-29 06:33:33 26 4
gpt4 key购买 nike

我正在尝试为 Magento 编写一个 SQL 查询,它将显示已支付的订单(非零总数)和基于优惠券的订单(零总数)。基于优惠券的订单应除以优惠券所来自的促销事件。然后报告的每一行显示如下:

  • 促销名称(购物车价格规则名称)
  • 订单数
  • 占订单总数的百分比
  • 平均订单总额

我意识到这可能是一个极其复杂的查询,所以如果有人指出我执行此查询所需的表,我会很高兴。欢迎并感谢任何帮助 =)

最佳答案

这似乎已经成功了

SELECT coupon_rule_name                         AS 'Promotion Used'
, coupon_code AS 'Code Used'
, COUNT(coupon_code) AS 'Times Used / Number of Orders'
, SUM(subtotal) AS 'Cumulative Price'

, SUM(total_paid) AS 'Cumulative Paid with Coupon'
, AVG(total_paid) AS 'Average Order Total (W/ Coupon)'
, AVG(subtotal) AS 'Average Order Total (W/O Coupon)'

, ABS(SUM(discount_amount)) AS 'Cumulative Savings'

, (
SUM(discount_amount) - SUM(total_paid)
) AS 'Cumulative Loss'

, CONCAT(ROUND((
COUNT(coupon_code) / (SELECT COUNT(*) FROM sales_flat_order s)
) * 100, 1), '%') AS 'Percentage'

FROM sales_flat_order
WHERE coupon_code IS NOT NULL
GROUP BY coupon_code
ORDER BY COUNT(coupon_code) DESC;

关于mysql - Magento 直接 SQL 查询基于优惠券的订单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26455273/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com