日期:2014-05-17 浏览次数:20784 次
with aa as
(select t.code, t.code_name from code t where t.code_type_id = 12),
bb as
(select t2.apply_type, t2.hospital_id, sum(cf.fee_amount) fee
from consult_fee cf
left join consult_booking t2
on cf.booking_id = t2.id
group by t2.apply_type, t2.hospital_id)
select t4.hospital_name, aa.code_name, t.counts, bb.fee, t4.balance
from (select t2.apply_type, t2.hospital_id, count(t1.id) counts
from consult_report t1
left join consult_booking t2
on t1.consult_booking_id = t2.id
left join consult_fee t3
on t2.id = t3.booking_id
left join doctor_info t4
on t1.expert_id = t4.id
where t1.consultation_status in (6, 7)
and t4.at_hospital_id = 100
and t2.hospital_id = 1
and t1.CONSULTATION_TIME between
to_date('2012-01-01', 'yyyy-mm-dd') and sysdate
group by t2.apply_type, t2.hospital_id) t
left join aa
on t.apply_type = aa.code
left join bb
on t.apply_type = bb.apply_type
left join hospital_info t4
on t.hospital_id = t4.id;