MYSQL总和与合并

时间:2017-07-02 10:19:48

标签: mysql sql

我有一个正确的工作查询,总计每个order_id的总数,见下文。但是如何在“Excl.BTW en Credit”和“Totaal BTW excl.Lede”的整个期间总计和

SELECT a.order_id AS "Ordernummer", 
       a.created_at AS "Orderdatum", 
       b.base_grand_total AS "Inclusief BTW", 
       b.base_tax_amount AS "Berekende BTW", 
       c.base_grand_total AS  "Credit-terugbetaald",
       (b.base_grand_total - 
          coalesce(c.base_grand_total, 0)) AS "Incl. BTW en Credit",
       ((b.base_grand_total - 
           coalesce(c.base_grand_total, 0)) - 
           (b.base_tax_amount - 
            coalesce(c.base_tax_amount, 0))) AS "Excl. BTW en Credit",
        (b.base_tax_amount - coalesce(c.base_tax_amount, 0)) AS "Totaal BTW excl. Credit"
FROM `sales_order_item` a 
INNER JOIN sales_invoice b ON a.order_id = b.order_id
LEFT JOIN sales_creditmemo c ON a.order_id = c.order_id
WHERE a.created_at > '2017-01-01'
GROUP BY a.order_id

0 个答案:

没有答案