hcjk_fr 查询SQL,支持组套
Posted 超轶绝尘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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}
以上是关于hcjk_fr 查询SQL,支持组套的主要内容,如果未能解决你的问题,请参考以下文章
sql [SQL查询片段]用于在命令行或通过R和其他工具使用SQL的快速代码段#tags:sql,R,text processing,命令li