需要查询一天查找每日交易的总和和计数

时间:2016-03-17 11:05:16

标签: mysql sql

    SELECT 
    S.merchant,
    S.TRAN_AMOUNT,
    S.TRAN_COUNT,
    S.DATE,
    A.MID,
    M.sales_person,
    M.mercinfo_legalname,
    M.mercinfo_dba_name,
    C.codedesc,
    AD.phoneno,
    AD.city,
    AD.state,
    AD.contact_name,
    TID
FROM
    (SELECT 
        t.merchant AS MERCHANT,
            SUM(t.f_txn_amount) AS TRAN_AMOUNT,
            COUNT(t.id_v2_wc_transaction) AS TRAN_COUNT,
            t.f_txn_datetime AS DATE
    FROM
        bijlipay.bij_v2_wc_transaction t
    WHERE
        t.f_txn_amount > 10
            AND DATE(t.f_txn_datetime) = '2016-03-08'
            AND t.f_trx_type = '1240/110'
    GROUP BY MERCHANT) S,
    bijlipay.bij_merchant M,
    bijlipay.bij_address AD,
    bijlipay.bij_codeset C,
    bijlipay.bij_device_allocation A
WHERE
    M.id_merchant = S.merchant
        AND AD.id_address = M.mercinfo_permanent_address
        AND C.codename = M.mercinfo_mcc
        AND A.merchant_id = S.merchant
GROUP BY S.MERCHANT;

这个查询结果我需要一天的总和和计数一个月

0 个答案:

没有答案