• 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}
  • 相关阅读:
    Oracle decode函数
    Flink笔记
    httpclient之put 方法(参数为json类型)
    XMLHTTPRequest的理解 及 SpringMvc请求和响应xml数据
    SQL获取本周,上周,本月,上月第一天和最后一天 注:本周从周一到周天
    Other
    Sql根据起止日期生成时间列表
    sql 在not in 子查询有null值情况下经常出现的陷阱
    sql 判断一个表的数据不在另一个表中
    查看系统触发器
  • 原文地址:https://www.cnblogs.com/guchunchao/p/11802685.html
Copyright © 2020-2023  润新知