我有一个这样的查询 -
SELECT
CONCAT(u.name, u.deviceAlias),
u.name,
u.deviceAlias,
j.description,
u.description AS vlanDescription
FROM
vlaninterfaces u,
interfacedescriptioninfo j
WHERE u.interfacedescriptioninfoid = j.id
AND u.deviceId = j.deviceId
AND u.interfaceNameAlias = j.name
AND j.toDevice NOT IN
(SELECT
deviceAlias
FROM
devices
WHERE siteId = 12)
AND u.deviceAlias IN
(SELECT
deviceAlias
FROM
devices
WHERE siteId = 12)
AND CONCAT(u.name, u.deviceAlias) NOT IN
(SELECT DISTINCT
CONCAT(v.name, fromDevice)
FROM
vlaninterfaces v,
interfacedescriptioninfo i
WHERE v.interfacedescriptioninfoid = i.id
AND v.deviceId = i.deviceId
AND v.interfacenameAlias = i.name
AND v.deviceAlias IN
(SELECT
deviceAlias
FROM
devices
WHERE siteId = 12)
AND v.interfacenameAlias LIKE '%ae%'
AND IF(
i.toDevice IS NULL,
i.interconnectedDevice,
i.toDevice
) IN
(SELECT
deviceAlias
FROM
devices
WHERE deviceClass = 'SWITCH'
AND siteId = 12))
GROUP BY CONCAT(u.name, u.deviceAlias) ;
我尝试使用 MINUS 但在 mysql 中发现我们不能使用这样的集合运算符。
在解释计划中,表 vlaninterfaces 不使用键并扫描所有行。
请通过示例告诉我 NOT IN 的替代方法(如果可能,请使用相同的查询)。