sql联合查询
Posted netlws
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql联合查询相关的知识,希望对你有一定的参考价值。
(SELECT affairs.* FROM affairs LEFT JOIN materials_details m ON affairs.AFFAIRID = m.AFFAIRID WHERE (((m.EXAMPLEPATH IS NOT NULL AND m.EXAMPLEPATH <> ‘‘) OR (m.EMPTYTABLEPATH IS NOT NULL AND m.EMPTYTABLEPATH <> ‘‘)) AND affairs.VALID = 1 AND affairs.AF_PARENT = -1 AND affairs.NodeType = 3 AND affairs.AF_DEPARTMENT = 4) GROUP BY affairs.AFFAIRID) UNION (SELECT * FROM affairs WHERE (AFFAIRID IN ( SELECT ff.AF_PARENT FROM ( SELECT AF_PARENT FROM affairs WHERE (AffairId IN ( SELECT tt.AffairId FROM ( SELECT a.AFFAIRID FROM affairs a LEFT JOIN materials_details m ON a.AFFAIRID = m.AFFAIRID WHERE (((m.EXAMPLEPATH IS NOT NULL AND m.EXAMPLEPATH <> ‘‘) OR (m.EMPTYTABLEPATH IS NOT NULL AND m.EMPTYTABLEPATH <> ‘‘)) AND a.VALID = 1 AND a.AF_DEPARTMENT = 4) ) tt ) AND AF_PARENT > 0 AND NodeType = 3) ) ff ) AND NodeType = 1 AND AF_PARENT = -1)) UNION (SELECT * FROM affairs WHERE (AFFAIRID IN ( SELECT uu.AF_PARENT FROM ( SELECT AF_PARENT FROM affairs WHERE (AFFAIRID IN ( SELECT ff.AF_PARENT FROM ( SELECT a.AF_PARENT FROM affairs a LEFT JOIN materials_details m ON a.AFFAIRID = m.AFFAIRID WHERE (((m.EXAMPLEPATH IS NOT NULL AND m.EXAMPLEPATH <> ‘‘) OR (m.EMPTYTABLEPATH IS NOT NULL AND m.EMPTYTABLEPATH <> ‘‘)) AND a.VALID = 1 AND a.AF_PARENT > 0 AND a.NodeType = 3 AND a.AF_DEPARTMENT = 4) GROUP BY a.AFFAIRID ) ff ) AND NodeType = 2 AND AF_PARENT > 0) ) uu ) AND NodeType = 1 AND AF_PARENT = -1))
以上是关于sql联合查询的主要内容,如果未能解决你的问题,请参考以下文章