按科室统计 2.181222版本 关联查询join 不对
SQL:
select
t0.deptName,
t0.deptId,
t0.startTime,
t0.endTime,
IFNULL(t0.num,0) as num0,
IFNULL(t1.num,0) as num1,
IFNULL(t2.num,0) as num2,
IFNULL(t4.num,0) as num4,
IFNULL(t5.num,0) as num5,
IFNULL(t6.num,0) as num6,
IFNULL(t7.num,0) as num7,
IFNULL(t8.num,0) as num8,
IFNULL(t9.num,0) as num9,
IFNULL(t10.num,0) as num10,
IFNULL(t11.num,0) as num11,
IFNULL(t13.num,0) as num13,
IFNULL(t14.num,0) as num14,
IFNULL(t15.num,0) as num15,
IFNULL(t16.num,0) as num16,
IFNULL(t17.num,0) as num17,
IFNULL(t18.num,0) as num18,
IFNULL(t19.num,0) as num19,
IFNULL(t20.num,0) as num20,
IFNULL(t21.num,0) as num21,
IFNULL(t22.num,0) as num22
from
-- ------------
-- 总挂号数
-- ------------
(
select t.startTime, t.endTime, count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.appointment_state,
a.dept_id as deptId, a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` and c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and f.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0
) t group by t.deptId
) t0 -- ------------
-- 退号
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId,
a.appointment_state,
a.dept_name as deptName,
CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` and c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete =0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and f.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.appointment_state = -1 ) t
group by t.deptId
) t1
on t0.deptId = t1.deptId -- ------------
-- 实际挂号数 = 初诊数 + 复诊数 + 转诊数
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.subsequent_visit in (0,1,2) ) t group by t.deptId
) t2
on t0.deptId = t2.deptId -- ------------
-- 初诊
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 0 ) t group by t.deptId
) t4
on t0.deptId = t4.deptId -- ------------
-- 复诊
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 1 ) t group by t.deptId
) t5
on t0.deptId = t5.deptId -- ------------
-- 体检
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 4 ) t group by t.deptId
) t6
on t0.deptId = t6.deptId -- ------------
-- 团队
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 7 ) t group by t.deptId
) t7
on t0.deptId = t7.deptId -- ------------
-- 简易
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 5 ) t group by t.deptId
) t8
on t0.deptId = t8.deptId -- ------------
-- 转诊
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 2 ) t group by t.deptId
) t9
on t0.deptId = t9.deptId -- ------------
-- 疫苗
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.subsequent_visit = 2
) t group by t.deptId
) t10
on t0.deptId = t10.deptId -- ------------
-- t11 微信数
-- ------------
left join
(
select count(1) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND a.data_source = 2 ) t group by t.deptId
) t11
on t0.deptId = t11.deptId -- ------------
-- 挂号费 t13
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0
) t group by t.deptId
) t13
on t0.deptId = t13.deptId -- ------------
-- 急诊费 t14
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND e.itemCode = 'jiajifei' -- 加急费:急诊费
) t group by t.deptId
) t14
on t0.deptId = t14.deptId -- ------------
-- 工本费 t15
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND e.itemCode = 'bingliben' -- 病历本:工本费
) t group by t.deptId
) t15
on t0.deptId = t15.deptId -- ------------
-- 卡费 t16
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 AND e.itemCode = 'jiuzhenka' -- 就诊卡:卡费
) t group by t.deptId
) t16
on t0.deptId = t16.deptId -- ------------
-- 现金 t17
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` and c.del_flag=0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and f.isDelete=0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 -- 门诊
and h.pay_method = 1 -- 银行卡
) t group by t.deptId
) t17
on t0.deptId = t17.deptId -- ------------
-- 银行卡 t18
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0
and h.pay_method = 2 -- 银行卡
) t group by t.deptId
) t18
on t0.deptId = t18.deptId -- ------------
-- 预检 t19
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 and e.itemCode = 'yujian' -- 预检:预存款
) t
group by t.deptId
) t19
on t0.deptId = t19.deptId -- ------------
-- 微信金额t20
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 and a.data_source = 2 ) t group by t.deptId
) t20
on t0.deptId = t20.deptId -- ------------
-- 应收金额 t21
-- ------------
left join
(
select round(sum(t.preFee),2) as num,t.deptId, t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee, -- 原价
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 ) t group by t.deptId
) t21
on t0.deptId = t21.deptId -- ------------
-- 实收金额 t22
-- ------------
left join
(
select round(sum(t.realFee),2) as num,t.deptId,t.deptName from
(
select
a.data_source,
a.is_appoint_resource,
a.subsequent_visit,
a.dept_id as deptId, a.appointment_state,
a.dept_name as deptName, CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime,
f.preFee,
(f.preFee - f.discountFee - f.promotionBenefitFee - f.couponFee - f.itemBenefitFee - f.memberCardBenefitFee - f.itemComInvBenefitFee) * f.discount AS realFee,
f.discount,
h.flow_fee,
h.`charge`,
h.`pay_method`
from `thc_arrange`.`bpm_appointment` a
inner join `thc_sob`.`bpm_service_order` b on a.orderId = b.id and b.del_flag = 0
inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id = b.id and c.id = a.`order_item_id` AND c.del_flag = 0
inner join `thc_rcm`.`Cs_AccountBill` d on d.orderID = b.id and d.`isDelete` = 0
inner join `thc_rcm`.`Cs_AccountBillDetail` e on d.id = e.AccountBillId and e.isDelete = 0
inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id and e.isDelete = 0
inner join `thc_rcm`.`Cs_Settlement` g on g.id = f.settlementID and g.settlementType=2 and g.`isDelete` = 0 -- 门诊挂号
inner join `thc_rcm`.`pay_trade_log` h on h.`settlement_id` = g.id and h.type = 1
where 1=1 and a.del_flag = 0 ) t
group by t.deptId
) t22
on t0.deptId = t22.deptId order by t0.startTime asc
按科室统计 2.181222版本 关联查询join 不对的更多相关文章
- SQL中order by;group up;like;关联查询join on的用法
排序order by的用法: 1.order by 字段名1 asc/desc, 字段名2 asc/desc,... 先按照字段名1的升序/降续给表进行排列 然后 按照字段名2的升序/降续给表进行排列 ...
- 关联查询 join on 和比较运算符 in
join on多表之间的关联查询 写法select 字段 from 表1 t join 表2 s on t.字段1 = s.字段1 where 条件: 也可以这么写select 字段 from 表1 ...
- 关联查询 join的使用
#!/usr/bin/env python import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.ext.dec ...
- tp5 thinkphp5 多表关联查询 join查询
model下: $res = \think\Db::name('article') ->alias("a") //取一个别名 ->join('admin ad','a. ...
- Mongoose如何实现统计查询、关联查询
[问题]Mongoose如何实现统计查询.关联查询 发布于 4 年前 作者 a272121742 13025 次浏览 最近业务上提出一个需求,要求能做统计,我们设计的文档集,统计可能跨越的文档会 ...
- 01-04-03【Nhibernate (版本3.3.1.4000) 出入江湖】Criteria API关联查询
Criteria API关联查询 如果说HQL查询还有需要了解点SQL语法知识,并不是完全彻底面向对象查询, 那么Criterial API就是完全面向对象的查询方式. public IList< ...
- [NHibernate]多对多关系(关联查询)
目录 写在前面 文档与系列文章 多对多关系关联查询 总结 写在前面 上篇文章介绍了nhibernate中对一对多关系进行关联查询的几种方式,以及在使用过程需要注意的问题.这篇文章对多对多关系的查询处理 ...
- 关于Entity Framework自动关联查询与自动关联更新导航属性对应的实体注意事项说明
一.首先了解下Entity Framework 自动关联查询: Entity Framework 自动关联查询,有三种方法:Lazy Loading(延迟加载),Eager Loading(预先加载) ...
- MySQL如何关联查询
总的来说,mysql认为任何一个查询都是一次关联,并不仅仅是一个查询需要用到两个表匹配才叫关联,所以,在mysql中,每一个查询,每一个片段(包括子查询,甚至单表select)都可能是关联.所以,理解 ...
随机推荐
- 【dfs】P1331 海战
题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...
- UVA10559 Blocks(区间dp)
有n个带有颜色的方块,没消除一段长度为x的连续的相同颜色的方块可以得到x^2的分数,让你用一种最优的顺序消除所有方块使得得分最多. 输入格式 第一行包含测试的次数t(1≤t≤15) 每个案例包含两行. ...
- sh: /etc/init.d/sshd: not found Docker中的Alpine镜像安装sshd无法启动
问题描述 在Alpine镜像中安装了openssh-server和openssh之后,无法执行ssh localhost.发现未启动服务,开启服务时报以下错误 / # ls /etc/init.d/s ...
- @Async的简单用法总结
前言: 在Java应用中,绝大多数情况下都是通过同步的方式来实现交互处理的:但是在处理与第三方系统交互的时 候,容易造成响应迟缓的情况,之前大部分都是使用多线程来完成此类任务,其实,在Spring 3 ...
- [luoguU48574][藏妹子之处]
题目链接 思路 首先,因为这是曼哈顿距离,所以很容易就可以将这三个点之间的距离转化为一个矩形,那么这三个点在矩形上的分布只有六种可能. 假设当前矩形的长为n,宽为m.那么可以发现,无论是哪一种情况,这 ...
- Unable to load script from assets 'index.android.bundle'.make sure you bundle is packaged correctly
解决此问题 以下方法每次都需要执行命令2才能更新 1.创建assets目录 mkdir android/app/src/main/assets 2.执行命令 react-native bundle - ...
- Linux批量修改(删除)文件名某些字符(rename命令)
假设在路径C:/下存在多个类似以下的文件名 file_nall_abc1.txt file_nall_abc2.txt file_nall_abc3.txt file_nall_abc4.txt fi ...
- 第二十七节,IOU和非极大值抑制
你如何判断对象检测算法运作良好呢?在这一节中,你将了解到并交比函数,可以用来评价对象检测算法. 一 并交比(Intersection over union ) 在对象检测任务中,你希望能够同时定位对象 ...
- CSS文档统筹
一.CSS文档统筹 1.整站里相同的CSS样式提取到一个样式表里,各个页面调用相同的样式文件即可: 2.网站较大的情况下一般会把网站的头部,尾部单独分离出来,包括样式文件: 1)根据页面类型分离文件 ...
- Flask简单学习
一:安装 直接 pip install Flask,就可以安装好了 二:hello world 编写一个hello.py # coding: utf- from flask import Flask ...