查询服务费sql

-- 查询服务费列表
SELECT t2.*,m.payoff_status AS payoffStatus FROM(
    SELECT
        t.custId,
        t.custName,
        t.monthStr,
        SUM( t.issueAmt ) AS issueTotalAmt,
        SUM( t.serviceFee ) AS serviceTotalFee,
        t.feePayoffDate,
        t.`year`,
        t.`month`
    FROM (
        SELECT
            k.`issuer` AS custId,
            c.cust_name AS custName,
            k.`issue_amt` AS issueAmt,
            k.service_fee AS serviceFee,
            k.fee_payoff_date AS feePayoffDate,
            YEAR ( k.fee_payoff_date ) AS `year`,
            MONTH ( k.fee_payoff_date ) AS `month`,
            CONCAT( YEAR ( k.fee_payoff_date ), '', MONTH ( k.fee_payoff_date ), '' ) AS monthStr 
        FROM lk_issue_info k
        LEFT JOIN cm_customer c ON k.`issuer` = c.cust_id 
        -- ${ew.customSqlSegment}
    ) t 
    GROUP BY t.custId,t.`month`,t.custName,t.monthStr,t.feePayoffDate
    ORDER BY t.monthStr DESC
) t2
LEFT JOIN cm_fee_mark m
ON m.cust_id = t2.custId
AND m.`year` = t2.`year`
AND m.`month` = t2.`month`

-- 查询服务费详情
SELECT
    k.issue_link_no AS linkNo,
    k.issue_amt AS issueAmt,
    c.cust_id AS custId,
    c.cust_name AS custName,
    k.issue_date AS issueDate,
    k.payoff_date AS payoffDate,
    k.link_days AS linkDays,
    k.service_fee_rate AS serviceFeeRate,
    k.service_fee AS serviceFee,
    k.fee_payoff_date AS feePayoffDate, 
    YEAR(k.fee_payoff_date) AS year, 
    MONTH(k.fee_payoff_date) AS month 
FROM lk_issue_info k
LEFT JOIN cm_customer c 
ON k.`issuer` = c.cust_id 
-- ${ew.customSqlSegment}

 

posted @ 2021-09-16 12:56  xuebusi  阅读(146)  评论(0编辑  收藏  举报