在线等,优化查询语句.急急!
select gzrq from [@hbu1skd]
where bh in (select skdh from [@hbu1skmx] where
(fybm= '续保费 'or fybm like '保险费% ')and
yfybh in (select bh from [@hbu4hkmx]
where year(fkq)=year( ' " + sjfkq + " ')
and month(fkq)=month( ' " + sjfkq + " ')
and pzh= ' " + PZH + " '))
能不能优化一下,提高执行效率.
------解决方案--------------------将in都换成exists
------解决方案--------------------尽量不要用in,把OR拆开,把对字段的操作都转换成对值的操作,效率就上去了
------解决方案--------------------select gzrq from [@hbu1skd],[@hbu1skmx],[@hbu4hkmx]
where [@hbu1skd].bh = [@hbu1skmx].skdh and [@hbu1skmx].fybm= '续保费 ' and
[@hbu1skd].yfybh = [@hbu4hkmx].bh and [@hbu4hkmx].fkq= ' " + sjfkq + " ' and
[@hbu4hkmx].fkq= ' " + sjfkq + " ' and [@hbu4hkmx].pzh= ' " + PZH + " '
union
select gzrq from [@hbu1skd],[@hbu1skmx],[@hbu4hkmx]
where [@hbu1skd].bh = [@hbu1skmx].skdh and [@hbu1skmx].fybm like '保险费% ' and
[@hbu1skd].yfybh = [@hbu4hkmx].bh and [@hbu4hkmx].fkq= ' " + sjfkq + " ' and
[@hbu4hkmx].fkq= ' " + sjfkq + " ' and [@hbu4hkmx].pzh= ' " + PZH + " '
--比方说上面这个,在日期转换那,你要看看怎么样就符合了过滤条件了