select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,exec_unit,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh from jx_zy_detail_charge_force where jx_zy_detail_charge_force.exec_unit not in (select description from jx_code_ctl where item_no like 'ordept%') and data_month='|datamonth|' union all select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,exec_unit,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh from jx_zy_detail_charge_force where jx_zy_detail_charge_force.exec_unit in (select description from jx_code_ctl where item_no like 'ordept%') and not ( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%') or jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|' union all select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh from jx_zy_detail_charge_force where jx_zy_detail_charge_force.exec_unit in (select description from jx_code_ctl where item_no like 'ordept%') and ( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%') or jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|' union all select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh from jx_zy_detail_charge_force where jx_zy_detail_charge_force.exec_unit is null and data_month='|datamonth|'
select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,exec_unit,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh from jx_zy_detail_charge_force where jx_zy_detail_charge_force.exec_unit not in (select description from jx_code_ctl where item_no like 'ordept%') and data_month='|datamonth|' union all select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,exec_unit,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh from jx_zy_detail_charge_force where jx_zy_detail_charge_force.exec_unit in (select description from jx_code_ctl where item_no like 'ordept%') and not ( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%') or jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|' union all select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh from jx_zy_detail_charge_force where jx_zy_detail_charge_force.exec_unit in (select description from jx_code_ctl where item_no like 'ordept%') and ( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%') or jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|' union all select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh from jx_zy_detail_charge_force where jx_zy_detail_charge_force.exec_unit is null and data_month='|datamonth|' 看你的sql中亮点,是like关键字太多了,这样对性能影响很大哦,能否把sql拆分,然后用程序处理你的结果集。
只与你的数据,php效率有关。
也有可能是你的代码写得效率低
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit not in (select description from jx_code_ctl where item_no like 'ordept%') and data_month='|datamonth|'
union all
select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,exec_unit,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit in (select description from jx_code_ctl where item_no like 'ordept%') and not
( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%') or
jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|'
union all
select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit in (select description from jx_code_ctl where item_no like 'ordept%') and
( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%') or
jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|'
union all
select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit is null and data_month='|datamonth|'
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit not in (select description from jx_code_ctl where item_no like 'ordept%') and data_month='|datamonth|'
union all
select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,exec_unit,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit in (select description from jx_code_ctl where item_no like 'ordept%') and not
( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%') or
jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|'
union all
select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit in (select description from jx_code_ctl where item_no like 'ordept%') and
( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%') or
jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|'
union all
select data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name,shenqingdh
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit is null and data_month='|datamonth|'
看你的sql中亮点,是like关键字太多了,这样对性能影响很大哦,能否把sql拆分,然后用程序处理你的结果集。
可以看下这篇文章,数据库优化
http://blog.csdn.net/timecolor/article/details/8887421