日期:2014-05-18 浏览次数:20732 次
--account_date时间列创聚集索引,zy_receipt表inpatient_no,admiss_times,ledger_sn建组合索引
--zy_detail_charge表inpatient_no,admiss_times,ledger_sn建组合索引,charge_code另建一索引
--zd_charge_item表Code建索引,zy_bill_item表建bill_item_code索引
SELECT
b.ward_code,
c.code,
sum(b.charge_fee)
FROM
zd_charge_item a
join
zy_detail_charge b on b.charge_code=a.Code
join
zy_bill_item c on a.bill_item_code=c.Code
where
exists(select 1 from zy_receipt where inpatient_no=b.inpatient_no and admiss_times=b.admiss_times and ledger_sn= b.ledger_sn
and account_date between '2007-01-01 ' and '2007-01-31 23:59:59') and b.charge_status=3 and b.ward_code='3020100'
group by
b.ward_code,c.code
------解决方案--------------------
使用存在谓词exists的效率比连接的效率高很多,它使用的内存小。