zoukankan      html  css  js  c++  java
  • hcjk_fr 查询SQL,支持组套

    hcjk_fr 查询SQL,支持组套

    select 
        t.itemName,
        t.patient_name,
        t.price,
        t.fatherItemClass,
        t.fatherItemClassName,
        t.createBy,
        t.createTime,
        sum(t.quantity)  as quantity,
        sum(t.totalMoney) AS totalMoney
        
    --     select *  
    from(
              -- 退费
              select 
                    b.itemID,
                    b.itemName,
                    d.`name` AS patient_name,
                    c.fatherItemClass,
                    c.fatherItemClassName,
                    k.docname as createBy,
                    DATE_FORMAT(a.createtime,'%Y-%m-%d') as createtime,
                    round(b.quantity) as quantity,
                    round(b.price,2) as price,
                    round(b.fee,2) AS totalMoney,
                    c.AccountBillId,
                    b.settlementID
                FROM  Cs_Settlement a
                JOIN Cs_SettlementDetail b on a.id = b.settlementID
                JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
                JOIN (
                    SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                    FROM thc_warehouse.staff_record u
                    LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = 'SXX000083' AND u.id = u1.staff_record_id 
                ) k     ON a.createBy = k.docid
                JOIN `thc_c_union`.`patient` d ON a.patientID = d.id
                
                where a.isDelete = 0 and a.returnFlag = 1 and b.itemID != 'VS00000000'  AND a.returnId="245e8eb18b584755bee1260b3753ec00" and c.packageId is null
                union
                -- 正向支付
                select 
                    b.itemID,
                    b.itemName,
                    d.`name` AS patient_name,
                    c.fatherItemClass,
                    c.fatherItemClassName,
                    k.docname as createBy,
                    DATE_FORMAT(a.createtime,'%Y-%m-%d') as createtime,
                    round(b.quantity) as quantity,
                    round(b.price,2) as price,
                    round(b.fee,2) AS totalMoney,
                    c.AccountBillId,
                    b.settlementID
                FROM  Cs_Settlement a
                JOIN Cs_SettlementDetail b on a.id = b.settlementID
                JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
                JOIN (
                    SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                    FROM thc_warehouse.staff_record u
                    LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = 'SXX000083' AND u.id = u1.staff_record_id
                ) k     ON a.createBy = k.docid
                JOIN `thc_c_union`.`patient` d ON a.patientID = d.id
                   where a.isDelete= 0 and a.returnFlag = 0   AND a.id="245e8eb18b584755bee1260b3753ec00"
                   and c.packageId is null
    ) t
    group by
        t.itemName,
        t.patient_name,
    --     t.price,
        t.fatherItemClass,
        t.fatherItemClassName
    --     t.createBy,
    --    t.createTime
    having (totalMoney > 0 and quantity > 0)
    
    
    union
    
    
    select 
        q.itemName,
        q.patient_name,
        sum(q.price) as price,
        q.fatherItemClass,
        q.fatherItemClassName,
        q.createBy,
        q.createTime,
        sum(q.quantity) as quantity,
        sum(q.totalMoney) AS totalMoney
    from(
    select 
        t.itemName,
        t.patient_name,
        sum(t.price) as price,
        t.fatherItemClass,
        t.fatherItemClassName,
        t.createBy,
        t.createTime,
        1 as quantity,
        sum(t.totalMoney) AS totalMoney
        
    --     select *  
    from(
              -- 退费
              select 
                    b.packageId as itemID,
                    b.packageName as itemName,
                    d.`name` AS patient_name,
                    c.fatherItemClass,
                    c.fatherItemClassName,
                    k.docname as createBy,
                    DATE_FORMAT(a.createtime,'%Y-%m-%d') as createtime,
                    round(b.quantity) as quantity,
                    round(b.price,2) as price,
                    round(b.fee,2) AS totalMoney,
                    c.AccountBillId,
                    b.settlementID
                FROM  Cs_Settlement a
                JOIN Cs_SettlementDetail b on a.id = b.settlementID
                JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
                JOIN (
                    SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                    FROM thc_warehouse.staff_record u
                    LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = 'SXX000083' AND u.id = u1.staff_record_id 
                ) k     ON a.createBy = k.docid
                JOIN `thc_c_union`.`patient` d ON a.patientID = d.id
                
                where a.isDelete = 0 and a.returnFlag = 1 and b.itemID != 'VS00000000'  AND a.returnId="245e8eb18b584755bee1260b3753ec00" and c.packageId is not null
                union
                -- 正向支付
                select 
                    b.packageId as itemID,
                    b.packageName as itemName,
                    d.`name` AS patient_name,
                    c.fatherItemClass,
                    c.fatherItemClassName,
                    k.docname as createBy,
                    DATE_FORMAT(a.createtime,'%Y-%m-%d') as createtime,
                    round(b.quantity) as quantity,
                    round(b.price,2) as price,
                    round(b.fee,2) AS totalMoney,
                    c.AccountBillId,
                    b.settlementID
                FROM  Cs_Settlement a
                JOIN Cs_SettlementDetail b on a.id = b.settlementID
                JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
                JOIN (
                    SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                    FROM thc_warehouse.staff_record u
                    LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = 'SXX000083' AND u.id = u1.staff_record_id
                ) k     ON a.createBy = k.docid
                JOIN `thc_c_union`.`patient` d ON a.patientID = d.id
                   where a.isDelete= 0 and a.returnFlag = 0   AND a.id="245e8eb18b584755bee1260b3753ec00"
                   and c.packageId is not null
    ) t
    group by
        t.itemName,
        t.patient_name,
    --     t.price,
        t.fatherItemClass,
        t.fatherItemClassName,
        t.AccountBillId
    --     t.createBy,
    --     t.createTime
    having (totalMoney > 0 and quantity > 0)
    
    ) q
    
    -- order by t.itemID limit 10 offset 0 -- ${startIndex}
  • 相关阅读:
    【杭电】[2035]人见人爱A^B
    【杭电】[2014]青年歌手大奖赛_评委会打分
    【杭电】[2014]青年歌手大奖赛_评委会打分
    【杭电】[2018]母牛的故事
    【杭电】[2018]母牛的故事
    SQL 01: 数据库表的三种关系
    History : The Age of the Samurai(11851868)
    History : Pictures of History 2
    JQuery 07 事件2
    JQuery 07 事件1
  • 原文地址:https://www.cnblogs.com/guchunchao/p/11802685.html
Copyright © 2011-2022 走看看