sql Magento 1 - SQL获取每个客户的销售和订单总数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql Magento 1 - SQL获取每个客户的销售和订单总数相关的知识,希望对你有一定的参考价值。

# Get the each customer sales and orders total

SELECT
    -- Round to two decimal places and prepend with $
    CONCAT('$', FORMAT(SUM(sales_flat_order.`grand_total`), 2)) AS 'Lifetime Sales',
    COUNT(sales_flat_order.entity_id) AS 'Orders',
    customer_entity.email AS 'Email',
    MAX(sales_flat_order.created_at) AS 'Most Recent Order Date'
FROM `customer_entity`
    LEFT JOIN sales_flat_order ON customer_entity.entity_id = sales_flat_order.customer_id
GROUP BY customer_entity.entity_id
ORDER BY SUM(sales_flat_order.`grand_total`) DESC
LIMIT 500;

# Get Orders Status

SELECT
    sales_order_status.label AS 'Status',
    COUNT(sales_flat_order.entity_id) AS 'Orders'
FROM sales_flat_order
    LEFT JOIN sales_order_status ON sales_flat_order.status = sales_order_status.status
GROUP BY sales_flat_order.status
ORDER BY COUNT(sales_flat_order.entity_id) DESC;

# Get the each month Order Status

SELECT
    -- "Year - Month"
    CONCAT(YEAR(sales_flat_order.created_at), ' - ', MONTHNAME(sales_flat_order.created_at)) AS 'Month',
    SUM(IF(`status` = 'canceled', 1, 0)) AS 'Canceled',
    SUM(IF(`status` = 'closed', 1, 0)) AS 'Closed',
    SUM(IF(`status` = 'complete', 1, 0)) AS 'Complete',
    -- Custom status
    SUM(IF(`status` = 'complete_partially_shipped', 1, 0)) AS 'Partially Shipped',
    SUM(IF(`status` = 'processing', 1, 0)) AS 'Processing',
    -- Custom status
    SUM(IF(`status` = 'shipped', 1, 0)) AS 'Shipped'
FROM sales_flat_order
GROUP BY MONTH(sales_flat_order.created_at);

以上是关于sql Magento 1 - SQL获取每个客户的销售和订单总数的主要内容,如果未能解决你的问题,请参考以下文章

php 从magento sql获取订单

sql SQL将管理员用户添加到Magento 1

sql Magento-1.7.2:删除所有订单和dashboard.sql

sql 清除所有Magento 1.9。*客户/订单数据

sql magento_removeAllCategories.sql

sql 清洁客户magento #magento #customer #clean