优化语句
这个语句SELECT STOCK_CODE,REPORT_END_DATE,FUNDCD,CLSDT,Naps,Accnav
FROM DATA_FUND_7010 T1 right join
(select fundcd,clsdt,Naps,Accnav from (SELECT FUNDCD,CLSDT,Naps,Accnav FROM H_csmar.csmar_data.dbo.CF_FDNTVAL
UNION ALL
SELECT FUNDCD,CLSDT,Naps,Accnav1 AS Accnav FROM H_csmar.csmar_data.dbo.OF_OFDDNTVAL
UNION ALL
SELECT FUNDCD,CLSDT,Maps AS Naps,Accmav AS Accnav FROM H_csmar.csmar_data.dbo.OF_OFDDMTVAL ) a where fundcd<>'37001b' and fundcd<>'37001B')T
on T1.STOCK_CODE=T.FUNDCD AND convert(VARCHAR(10),T1.REPORT_END_DATE,120)=T.CLSDT
where t1.STOCK_CODE is null ORDER BY CLSDT DESC
表里有100万数据,跑了半个小时,能不能 优化一下?
不要用update 替换null,这个我试了,效率提高了很多, 从30分钟变为1分钟,但是我们头不建议这么做
------最佳解决方案--------------------SELECT STOCK_CODE,REPORT_END_DATE,FUNDCD,CLSDT,Naps,Accnav
FROM (Select STOCK_CODE,REPORT_END_DATE,FUNDCD,CLSDT,Naps,Accnav
From DATA_FUND_7010 Where isNull(STOCK_CODE,'') = '') T1 right join
(select fundcd,clsdt,Naps,Accnav from (SELECT FUNDCD,CLSDT,Naps,Accnav FROM H_csmar.csmar_data.dbo.CF_FDNTVAL Where isNull(fundcd,'') = ''
UNION ALL
SELECT FUNDCD,CLSDT,Naps,Accnav1 AS Accnav FROM H_csmar.csmar_data.dbo.OF_OFDDNTVAL Where isNull(fundcd,'') = ''
UNION ALL
SELECT FUNDCD,CLSDT,Maps AS Naps,Accmav AS Accnav FROM H_csmar.csmar_data.dbo.OF_OFDDMTVAL Where isNull(fundcd,'') = ''
) a where fundcd<>'37001b' and fundcd<>'37001B')T
on convert(VARCHAR(10),T1.REPORT_END_DATE,120)=T.CLSDT
ORDER BY CLSDT DESC
------其他解决方案-------------------- where t1.STOCK_CODE is null 楼主是不是写反了,如果STOCK_CODE 为Null而且T1.STOCK_CODE=T.FUNDCD ,那么FUNDCD 也为Null, 这样还需还T1.STOCK_CODE=T.FUNDCD条件比对吗,不是浪费时间吗
------其他解决方案--------------------你的union all不用吧?还有那么多<>,所以都无效了
------其他解决方案--------------------好吧 结贴了