title: Optimize SQL Query to avoid Hash Match (Aggregate)
body: <p>I have a SQL query that takes 7 minutes+ to return results.  I'm trying to optimize as much as possible and the Execution plan loses 82% of the time on a Hash Match (Aggregate).  I've done some searching and looks like using an "EXISTS" would help to resolve, but I haven't figured out the syntax of the query to make it work.  Here's the query:</p>
  
  <pre><code>select dbo.Server.Name,
                  dbo.DiskSpace.Drive,
                  AVG(dbo.DiskSpace.FreeSpace) as 'Free Disk Space',
                  AVG(dbo.Processor.PercentUsed) as 'CPU % Used',
                  AVG(dbo.Memory.PercentUtilized) as '% Mem Used'
  
                  from Server
                  join dbo.DiskSpace on dbo.Server.ID=DiskSpace.ServerID
                  join dbo.Processor on dbo.Server.ID=Processor.ServerID
                  join dbo.Memory on dbo.Server.ID=dbo.Memory.ServerID
  
                  where
                  dbo.Processor.ProcessorNum='_Total' 
                      and dbo.Processor.Datetm&gt;DATEADD(DAY,-(1),(CONVERT (date, GETDATE()))) 
                      and (      dbo.Server.Name='qp-ratking' 
                              or dbo.Server.Name='qp-hyper2012' 
                              or dbo.Server.Name='qp-hyped' 
                              or dbo.Server.Name='qp-lichking')
                  Group By dbo.server.name, Dbo.DiskSpace.Drive
                  Order By Dbo.Server.Name, dbo.DiskSpace.Drive;
  </code></pre>
  
  <p>How do I reduce/eliminate the joins using EXISTS? Or if there is a better way to optimize, I'm up for that too.  Thanks</p>