SELECT *
FROM sec
WHERE sec.cu IN (SELECT s.cu
FROM sec s WITH (nolock)
WHERE EXISTS (SELECT *
FROM hact h WITH ( nolock),
JOIN dport p WITH ( nolock) ON h.ic = p.ic
WHERE s.cu = h.cu )
UNION
SELECT s.cu
FROM sec s WITH (nolock)
WHERE EXISTS(SELECT *
FROM schanges c WITH ( nolock)
WHERE s.cu = c.cu)
UNION
SELECT s.cu
FROM sec s WITH (nolock)
WHERE s.cu IN (SELECT DISTINCT cu
FROM suk WITH (nolock)))
AND EXISTS (SELECT *
FROM hact h WITH (nolock)
JOIN port p WITH (nolock)
ON h.ic = p.ic
WHERE sec.cu = h.cu
AND p.ptype = 'X')
嗨,我有这个查询,我正在尝试优化。我试图将其转换为删除联合和 In 以更具可读性但失败了。我正在努力提高效率,可能只使用 EXISTS 和 NOT EXISTS。