帆软报表SQL怎么优化下,现在的SQL执行效率太低了,有时候都超时了
select
cc.科室 科室,
sum(cc.本月累计) 本月累计,
sum(cc.全部累计) 全部累计,
sum(cc.本月推荐累计) 本月推荐累计,
sum(cc.全部推荐累计) 全部推荐累计
from
(select
bb.科室,
sum(bb.本月累计) 本月累计,
sum(bb.全部累计) 全部累计,
sum(bb.本月推荐累计) 本月推荐累计,
sum(bb.全部推荐累计) 全部推荐累计
from
(select
${if(fl=1,"decode(ks.chinese_name,null,'挂号未就诊','药剂科','便民药房','便民药房门诊','便民药房',ks.chinese_name)||' '||decode(hrm.employee_name,null,'挂号未就诊',hrm.employee_name)","decode(ks.chinese_name,null,'挂号未就诊','药剂科','便民药房','便民药房门诊','便民药房',ks.chinese_name)")} 科室,
count(distinct case when to_date(to_char(aa.sj,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date('${starttime} ','yyyy-mm-dd')
and to_date(to_char(aa.sj,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('${endtime} ','yyyy-mm-dd') then aa.id end) 本月累计,
count(distinct case when to_date(to_char(aa.sj,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date(to_char(to_date('${starttime} ','yyyy-mm-dd'),'yyyy')||'01'||'01','yyyy-mm-dd')
and to_date(to_char(aa.sj,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('${endtime} ','yyyy-mm-dd') then aa.id end) 全部累计,
count(distinct case when to_date(to_char(aa.djsj,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date('${starttime} ','yyyy-mm-dd')
and to_date(to_char(aa.djsj,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('${endtime} ','yyyy-mm-dd') then aa.zyid end) 本月推荐累计,
count(distinct case when to_date(to_char(aa.djsj,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date(to_char(to_date('${starttime} ','yyyy-mm-dd'),'yyyy')||'01'||'01','yyyy-mm-dd')
and to_date(to_char(aa.djsj,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('${endtime} ','yyyy-mm-dd') then aa.zyid end) 全部推荐累计
from
(select
opr.id id,
ipi.id zyid,
ipi.registration_date djsj,
opr.registration_date sj,
opr.clinic_dept_id kdks,
nvl(opc.doctor_id,opr.doctor_id) kdys
from opr_registration opr
left join opr_registration_d oprd on oprd.opr_registration_id=opr.id
left join opc_registration opc on opc.opr_registration_id=opr.id
left join hrm_employee hrm on hrm.id=opr.doctor_id
left join ipi_registration ipi on ipi.ipi_doctor_id=hrm.id
and ipi.s_brztbh_dm!='70'
where opr.id not in (select dd.opr_registration_id from opr_registration_d dd where dd.registration_d_id is not null )
--and opc.department_id!='bb8c2cd44d8080819c90'
)aa
left join opr_clinic_department ks on ks.id=aa.kdks
left join hrm_employee hrm on aa.kdys=hrm.id
group by ks.chinese_name,hrm.employee_name
)bb
group by bb.科室
union all
select
bb.科室,
sum(bb.本月累计) 本月累计,
sum(bb.全部累计) 全部累计,
sum(bb.本月推荐累计) 本月推荐累计,
sum(bb.全部推荐累计) 全部推荐累计
from
(select
${if(fl=1,"decode(dpte.department_chinese_name,null,'挂号未就诊','药剂科','便民药房','便民药房门诊','便民药房',dpte.department_chinese_name)||' '||decode(hrm.employee_name,null,'挂号未就诊',hrm.employee_name)","decode(dpte.department_chinese_name,null,'挂号未就诊','药剂科','便民药房','便民药房门诊','便民药房',dpte.department_chinese_name)")} 科室,
count(distinct case when to_date(to_char(aa.sj,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date('${starttime} ','yyyy-mm-dd')
and to_date(to_char(aa.sj,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('${endtime} ','yyyy-mm-dd') then aa.id end) 本月累计,
count(distinct case when to_date(to_char(aa.sj,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date(to_char(to_date('${starttime} ','yyyy-mm-dd'),'yyyy')||'01'||'01','yyyy-mm-dd')
and to_date(to_char(aa.sj,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('${endtime} ','yyyy-mm-dd') then aa.id end) 全部累计,
count(distinct case when to_date(to_char(aa.djsj,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date('${starttime} ','yyyy-mm-dd')
and to_date(to_char(aa.djsj,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('${endtime} ','yyyy-mm-dd') then aa.zyid end) 本月推荐累计,
count(distinct case when to_date(to_char(aa.djsj,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date(to_char(to_date('${starttime} ','yyyy-mm-dd'),'yyyy')||'01'||'01','yyyy-mm-dd')
and to_date(to_char(aa.djsj,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('${endtime} ','yyyy-mm-dd') then aa.zyid end) 全部推荐累计
from
(select
opr.id id,
ipi.id zyid,
ipi.registration_date djsj,
opr.registration_date sj,
opc.department_id kdks,
nvl(opc.doctor_id,opr.doctor_id) kdys
from opr_registration opr
left join opr_registration_d oprd on oprd.opr_registration_id=opr.id
left join opc_registration opc on opc.opr_registration_id=opr.id
left join hrm_employee hrm on hrm.id=opr.doctor_id
left join ipi_registration ipi on ipi.ipi_doctor_id=hrm.id
and ipi.s_brztbh_dm!='70'
where opr.id not in (select dd.opr_registration_id from opr_registration_d dd where dd.registration_d_id is not null )
and opc.department_id='bb8c2cd44d8080819c90'
)aa
left join hra00_department dpte on dpte.id=aa.kdks
left join hrm_employee hrm on aa.kdys=hrm.id
group by dpte.department_chinese_name,hrm.employee_name
)bb
group by bb.科室
)cc
group by 科室
--${if(px=5,"order by 科室 desc","")}
${if(px=1,"order by 科室,本月累计 desc","order by 科室")}
${if(px=2,"order by 科室,全部累计 desc","")}
${if(px=3,"order by 科室,本月推荐累计 desc","")}
${if(px=4,"order by 科室,全部推荐累计 desc","")}
...全文
相关推荐
Sql Server 数据库超时问题的解决方法
Sql server 2000 的等待响应时间
非常试用的SQL优化技巧
非常试用的SQL优化技巧非常试用的SQL优化技巧
oracle parallel SQL
oracle parallel SQL,oracle parallel SQL
sqlcheck:自动识别SQL查询中的反模式
sqlcheck:自动识别SQL查询中的反模式
SQL Server安装完成后3个需要立即修改的配置选项
你用安装向导安装了全新的SQL Server,最后你点击了完成按钮。哇噢~~~现在我们可以把我们的服务器进入生产了!抱歉,那并不是真的,因为你的全新SQL Server默认配置是错误的。 是的,你没看错:SQL Server的默认安装在很多方面的配置是错误的。在今天的文章里,我想给你展示下,为了更快的性能,在SQL Server安装完成后3个你需要立即修改的配置选项。我们开始吧! 最大服务器内存(Max Server Memory) 免责声明:如果这些天你在32位系统上运行你的SQL Server,请扔掉你的硬件,买个64位的系统,安装64位的SQL Server,然后从这里继续读。 现在在你


数据库报表
