需求:两张表:一张故障表,一张故障类别表,故障类别表为级联表,现在统计故障表中某一类别(这里为最高节点,parentID为0)的数据有多少,真实SQL如下:
SELECT COUNT(1) FROM (SELECT D.EVENTID FROM DE_NFAULT_201707 D WHERE D.EVENTID IN (SELECT C.EVENTCATEID FROM CP_NFAULTEVENT C START WITH C.PARENTID = 0 CONNECT BY PRIOR C.EVENTCATEID = C.PARENTID))
DE_NFAULT_201707为故障表,CP_NFAULTEVENT为故障级别表