子查询太影响效率了,有大神能帮忙看看么?可以怎么优化?
SELECT
dw.NAME AS dwname,
dzz.NAME AS dzzname,
t.*
FROM
tbl_i_dzz dw
LEFT JOIN
(SELECT
izbhd.tfid tfid,
izbhd.hdsj,
(YEAR(CURDATE()) - YEAR(izbhd.hdsj)) * 12 - MONTH(izbhd.hdsj) + MONTH(CURDATE()) AS result,
izbhd.dzzid, izbhd.hdyt, izbhd.hddd, izbhd.hdxxId, izbhd.zcr, izbhd.yddy, izbhd.sddy, izbhd.zw,
izbhd.tplj, izbhd.yplj, izbhd.zttplj, izbhd.sfpl, izbhd.pls, izbhd.dzs, izbhd.scs, izbhd.lll, izbhd.yddyrs,
izbhd.sddyrs, izbhd.dwid, izbhd.deleteFlag , izbhd.createDT
FROM
tbl_i_zbhd izbhd
WHERE izbhd.tfid IN
(SELECT
MAX(tfid)
FROM
tbl_i_zbhd
WHERE hdsj IN
(SELECT
MAX(hdsj)
FROM
tbl_i_zbhd
WHERE DeleteFlag='0'
GROUP BY
<isEqual property="DW" compareValue="1">
dwid
</isEqual>
<isEqual property="DW" compareValue="0">
dzzid
</isEqual>
) and DeleteFlag='0'
GROUP BY
<isEqual property="DW" compareValue="1">
dwid
</isEqual>
<isEqual property="DW" compareValue="0">
dzzid
</isEqual>
)
AND DeleteFlag='0'
) t
ON dw.TFID = t.dwid AND t.deleteFlag = '0'
LEFT JOIN
tbl_i_dzz dzz
ON t.dzzid = dzz.TFID
WHERE dw.DeleteFlag='0'
AND getdzzlevel(dw.allpid,';')=2
<isNotEmpty prepend="and" property="dwid">
dw.tfid=#dwid#
</isNotEmpty>
<isNotEmpty prepend="and" property="dwname">
dw.NAME LIKE '%$dwname$%'
</isNotEmpty>
<isNotEmpty prepend="and" property="dzzname">
dzz.NAME LIKE '%$dzzname$%'
</isNotEmpty>
<isNotEmpty prepend="and" property="zw">
t.zw LIKE '%$zw$%'
</isNotEmpty>
<isNotEmpty prepend="Order By" property="order">
$order$
</isNotEmpty>
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。