如何在不同条件下两次选择总和值

时间:2019-07-18 15:36:57

标签: sql

我想对此代码进行比较查询:

我想选择

    SUM(TOTALCHKS) ORDERS,
    SUM(AMOUNT) GrossAmount,
    SUM(AMOUNT - COMPS - PROMOS) Amount,
    SUM(NET) NetAmount,
    SUM(INCLTAX) InclTax,

再次,但条件不同。请查看我的代码:

SELECT      
    STR_NAME,
    DOB,
    SUM(TOTALCHKS) ORDERS,
    SUM(AMOUNT) GrossAmount,
    SUM(AMOUNT - COMPS - PROMOS) Amount,
    SUM(NET) NetAmount,
    SUM(INCLTAX) InclTax,
    Average = (sum (AMOUNT) /sum(TOTALCHKS))
FROM
    CR_TOTLCKS 
INNER JOIN
    CR_STORE ON COMPANY = STR_COMPANY 
             AND BRAND = STR_BRAND AND UNIT =STR_NO
WHERE
    COMPANY = 1 
    AND BRAND = 1 
    AND DOB BETWEEN '2019-07-01' AND '2019-07-01' 
    AND UNIT IN (1) 
GROUP BY
    STR_NAME,
    DOB

请-有人可以帮助我吗?

0 个答案:

没有答案