存储过程的优化.........
CREATE PROCEDURE REPORT_COUNT3
(@start_datem nvarchar(20),
@end_datem nvarchar(20) )
AS
select '統計(總) ' as 統計, sum(d1.ps) as ps,sum(d1.weig) as weig,sum(d1.charge) as charge from (select d.c3,sum(d.ps) as ps,sum(d.weig) as weig,sum(d.charge) as charge from (select case when m.loc_code is null then s.stano else m.loc_code end as loc_code,s.station,s.c3,
isnull(m.ps,0) as ps,isnull(m.weig,0) as weig,isnull(m.charge,0) as charge from
(select loc_code,count(*) as ps,sum(weig) as weig,sum(charge) as charge from manifest where datem between
@start_datem and @end_datem group by loc_code) m full outer join stat s on m.loc_code=s.stano) d group by c3) d1
GO
各位帮忙看一下,有那里需要改进的地方,TKS
------解决方案--------------------感觉没什么可优化的了,楼主的派生表写法正常。
业务上的问题看不出来。
------解决方案--------------------有好几重子查询。。。