sql Magento - 按月和年度分类的所有订单总和包括折扣总和

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql Magento - 按月和年度分类的所有订单总和包括折扣总和相关的知识,希望对你有一定的参考价值。

SELECT sub_query.month_ordered,
       sub_query.year_ordered,
       SUM(sub_query.base_subtotal) AS sum_base_subtotal,
       SUM(sub_query.discount_amount) AS sum_discount_amt,
       SUM(sub_query.order_qty) AS sum_total_item_count,
       COUNT(sub_query.entity_id) AS total_orders
FROM
  (SELECT so.entity_id,
          MONTH(so.created_at) AS month_ordered,
          YEAR(so.created_at) AS year_ordered,
          so.base_subtotal,
          so.discount_amount,
          so.total_item_count AS order_qty,
          so.increment_id
   FROM `sales_flat_order` AS so
   INNER JOIN `sales_flat_order_item` AS si ON si.order_id=so.entity_id
   GROUP BY entity_id) AS sub_query
GROUP BY sub_query.month_ordered
ORDER BY year_ordered DESC,
         month_ordered DESC

以上是关于sql Magento - 按月和年度分类的所有订单总和包括折扣总和的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Jooq 中按月和年将毫秒翻译成日期和分组?

Django按月和年过滤

仅按月和年选择数据

按月和日期比较两个日期Python

按月和日过滤 django 日期时间字段的问题

pandas:按月和天匹配数据