我需要一些帮助来优化下面的查询。查询的主要思想是我需要运行一组计算机(a.group =' 3008000204')以找出选择组中哪些计算机没有列出的应用程序(app_id)他们和我也想确保他们不是一个单独的机器列表(其中a.mach_name不是IN)的一部分。
有更好的方法吗?
SELECT mach_name, costcenter, mach_type, make, model, opsys, firstname, lastname, userid,
CASE WHEN NOT EXISTS(select 1 from Workstations f
where a.mach_name not IN('WD-KSA699YBK625','WN-MN14GLY8E00U','WN-MN14GLY8E950','WN-MN14GLY8E00R','WN-MNA79GY0V0DM','WN-MNA79GY0V0E2','WN-MNA79GY0V0J4','WN-MNA79GY0V808','WN-MN14GLY8E0J5','WN-MN14GLA66532','WN-MNA79GY0V0E7','WN-MNA79GY0V01D')
)
THEN 'yes'
ELSE 'no'
END as dups,
CASE WHEN NOT EXISTS(SELECT 1 FROM Workstations d
left join Assignments e
on d.WsID = e.WsID
where a.mach_Name = d.Mach_Name
and e.app_id in( 15317,15340,12998,13001,15429)
)
THEN 'yes'
ELSE 'no'
END AS readycheck
FROM Workstations a
where a.group = '3008000204'
and ((a.opsys != 'OS X')
and (a.mach_type != 'V')
and (a.opsys != 'Windows 10'))