Question

this is my query:

SELECT
   FORMAT(SUM(`s`.`grand_total`), 2) AS `sum`
FROM `sales_flat_order` `s`
WHERE 
      `s`.`grand_total` > 0 AND
      `s`.`state` =  'complete'
ORDER BY SUM(`s`.`base_total_invoiced`) DESC

but result of this query does not match Lifetime Sales from dashboard page. Any idea why ?

Thx

Was it helpful?

Solution

Magento.. default dash board life time sales total are taken from Report Model.it does not taken directly from sales_flat_order grand total

There are some complex logic behind it left time sales:

SELECT
   SUM((IFNULL(main_table.base_total_invoiced, 0) - IFNULL(main_table.base_tax_invoiced, 0) - IFNULL(main_table.base_shipping_invoiced, 0) - (IFNULL(main_table.base_total_refunded, 0) - IFNULL(main_table.base_tax_refunded, 0) - IFNULL(main_table.base_shipping_refunded, 0))) * main_table.base_to_global_rate) AS `lifetime`,
   AVG((IFNULL(main_table.base_total_invoiced, 0) - IFNULL(main_table.base_tax_invoiced, 0) - IFNULL(main_table.base_shipping_invoiced, 0) - (IFNULL(main_table.base_total_refunded, 0) - IFNULL(main_table.base_tax_refunded, 0) - IFNULL(main_table.base_shipping_refunded, 0))) * main_table.base_to_global_rate) AS `average` 
FROM
   `sales_flat_order` AS `main_table` 
WHERE
   (
      main_table.status NOT IN
      (
         'canceled'
      )
   )
   AND 
   (
      main_table.state NOT IN
      (
         'new',
         'pending_payment'
      )
   )
limit 0,1
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top