Query to get the top buyers in Magento 2

SELECT `sales_order`.`customer_id`, `email`, `firstname`, `lastname`, `telephone`, `street`, `city`, `region`, `company`, SUM(subtotal_invoiced) 
FROM (`sales_order` LEFT JOIN `sales_order_address` ON `sales_order`.`entity_id` = `sales_order_address`.`parent_id` AND `sales_order_address`.`address_type` = "billing") 
WHERE state = "complete" AND store_id = 1 
GROUP BY customer_email ORDER BY SUM(subtotal_invoiced) DESC LIMIT 100

magento2 top buyers query

Note: If customer_id is NULL so it’s the guest user.

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments