根据部门及医生分组查询

 

 

select 
    t0.deptName, 
    t0.doctorName,
    IFNULL(t0.num,0) as num0,
    IFNULL(t1.num,0) as num1,
    IFNULL(t2.num,0) as num2,
    IFNULL(t3.num,0) as num3,
    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(t10.num,0) as num14,
    IFNULL(t11.num,0) as num15,
    IFNULL(t13.num,0) as num16,
    IFNULL(t10.num,0) as num17,
    IFNULL(t13.num,0) as num18,
    IFNULL(t10.num,0) as num19

from 
-- ------------
-- 总挂号数
-- ------------
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    (
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.appointment_state,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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
    ) t
    group by t.deptId,t.doctorId
) t0

-- ------------
-- 退号
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.appointment_state = -1
    ) t 
    group by t.deptId,t.doctorId
) t1
on t0.deptId = t1.deptId and t0.doctorId = t1.doctorId

-- ------------
-- 实际挂号数   =    初诊数 + 复诊数 + 转诊数
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.subsequent_visit in (0,1,2)
    ) t 
    group by t.deptId,t.doctorId
) t2
on t0.deptId = t2.deptId and t0.doctorId = t2.doctorId

-- ------------
-- 指定
-- ------------    
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.is_appoint_resource = 1
    ) t 
    group by t.deptId,t.doctorId
) t3
on t0.deptId = t3.deptId and t0.doctorId = t3.doctorId


-- ------------
-- 初诊
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.subsequent_visit = 0
    ) t 
    group by t.deptId,t.doctorId
) t4
on t0.deptId = t4.deptId and t0.doctorId = t4.doctorId

-- ------------
-- 复诊
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.subsequent_visit = 1
    ) t 
    group by t.deptId,t.doctorId
) t5
on t0.deptId = t5.deptId and t0.doctorId = t5.doctorId



-- ------------
-- 复诊
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.subsequent_visit = 4
    ) t 
    group by t.deptId,t.doctorId
) t6
on t0.deptId = t6.deptId and t0.doctorId = t6.doctorId

-- ------------
-- 团队
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.subsequent_visit = 7
    ) t 
    group by t.deptId,t.doctorId
) t7
on t0.deptId = t7.deptId and t0.doctorId = t7.doctorId


-- ------------
-- 简易 
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.subsequent_visit = 5
    ) t 
    group by t.deptId,t.doctorId
) t8
on t0.deptId = t8.deptId and t0.doctorId = t8.doctorId



-- ------------
-- 转诊
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.subsequent_visit = 2
    ) t 
    group by t.deptId,t.doctorId
) t9
on t0.deptId = t9.deptId and t0.doctorId = t9.doctorId

-- ------------
-- 疫苗
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.subsequent_visit = 2
    ) t 
    group by t.deptId,t.doctorId
) t10
on t0.deptId = t10.deptId and t0.doctorId = t10.doctorId

-- ------------
-- 微信
-- ------------
left join 
(
    select count(1) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.data_source = 2
    ) t 
    group by t.deptId,t.doctorId
) t11
on t0.deptId = t11.deptId and t0.doctorId = t11.doctorId

-- ------------
-- 挂号费 t12
-- ------------



-- ------------
-- 急诊
-- ------------
left join 
(
    select round(sum(t.realFee),2) as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 e.`itemCode` = 'jiajifei'    -- 加急费:急诊费
    ) t 
    group by t.deptId,t.doctorId
) t13
on t0.deptId = t13.deptId and t0.doctorId = t13.doctorId

-- ------------
-- 工本费 t14
-- ------------
left join 
(
    select round(sum(t.realFee),2)  as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 e.`itemCode` = 'bingliben'    -- 病历本:工本费
    ) t 
    group by t.deptId,t.doctorId
) t14
on t0.deptId = t14.deptId and t0.doctorId = t14.doctorId

-- ------------
-- 卡费 t15
-- ------------
left join 
(
    select round(sum(t.realFee),2)  as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 e.`itemCode` = 'jiuzhenka'    -- 病历本:工本费
    ) t 
    group by t.deptId,t.doctorId
) t15
on t0.deptId = t15.deptId and t0.doctorId = t15.doctorId


-- ------------
-- 现金 t16
-- ------------
left join 
(
    select round(sum(t.realFee),2)  as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 h.pay_method = 1      -- 现金
    ) t 
    group by t.deptId,t.doctorId
) t16
on t0.deptId = t16.deptId and t0.doctorId = t16.doctorId

-- ------------
-- 刷卡 t17
-- ------------
left join 
(
    select round(sum(t.realFee),2)  as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 h.pay_method = 2      -- 银行卡
    ) t 
    group by t.deptId,t.doctorId
) t17
on t0.deptId = t17.deptId and t0.doctorId = t17.doctorId

-- ------------
-- 预存款 t18
-- ------------
left join 
(
    select round(sum(t.realFee),2)  as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 e.`itemCode` = 'yujian' -- 预检:预存款
    ) t 
    group by t.deptId,t.doctorId
) t18
on t0.deptId = t18.deptId and t0.doctorId = t18.doctorId



-- ------------
-- 预存款 t19
-- ------------
left join 
(
    select round(sum(t.realFee),2)  as num,t.deptId, doctorId,t.deptName,t.doctorName from
    ( 
        select 
            a.data_source,
            a.is_appoint_resource,
            a.subsequent_visit,
            a.dept_id as deptId,
            a.appointment_doctor_id as doctorId,
            a.appointment_state,
            a.dept_name as deptName,
            a.appointment_doctor_name as doctorName, 
            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
        inner join `thc_sob`.`bpm_service_order_item` c on c.service_order_id =  b.id and c.id = a.`order_item_id`
        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
        inner join `thc_rcm`.`Cs_SettlementDetail` f on f.accountBillID = d.id and f.accountBillDetailID = e.id
        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 a.data_source = 2
    ) t 
    group by t.deptId,t.doctorId
) t19
on t0.deptId = t19.deptId and t0.doctorId = t19.doctorId

 

转载于:https://www.cnblogs.com/guchunchao/p/10145013.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GeoPandas是一个开源的Python库,旨在简化地理空间数据的处理和分析。它结合了Pandas和Shapely的能力,为Python用户提供了一个强大而灵活的工具来处理地理空间数据。以下是关于GeoPandas的详细介绍: 一、GeoPandas的基本概念 1. 定义 GeoPandas是建立在Pandas和Shapely之上的一个Python库,用于处理和分析地理空间数据。 它扩展了Pandas的DataFrame和Series数据结构,允许在其中存储和操作地理空间几何图形。 2. 核心数据结构 GeoDataFrame:GeoPandas的核心数据结构,是Pandas DataFrame的扩展。它包含一个或多个列,其中至少一列是几何列(geometry column),用于存储地理空间几何图形(如点、线、多边形等)。 GeoSeries:GeoPandas中的另一个重要数据结构,类似于Pandas的Series,但用于存储几何图形序列。 二、GeoPandas的功能特性 1. 读取和写入多种地理空间数据格式 GeoPandas支持读取和写入多种常见的地理空间数据格式,包括Shapefile、GeoJSON、PostGIS、KML等。这使得用户可以轻松地从各种数据源中加载地理空间数据,并将处理后的数据保存为所需的格式。 2. 地理空间几何图形的创建、编辑和分析 GeoPandas允许用户创建、编辑和分析地理空间几何图形,包括点、线、多边形等。它提供了丰富的空间操作函数,如缓冲区分析、交集、并集、差集等,使得用户可以方便地进行地理空间数据分析。 3. 数据可视化 GeoPandas内置了数据可视化功能,可以绘制地理空间数据的地图。用户可以使用matplotlib等库来进一步定制地图的样式和布局。 4. 空间连接和空间索引 GeoPandas支持空间连接操作,可以将两个GeoDataFrame按照空间关系(如相交、包含等)进行连接。此外,它还支持空间索引,可以提高地理空间数据查询的效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值