Avatar of Jeffrey Renfroe
Jeffrey Renfroe
Flag for United States of America

asked on 

Display Top 5 using MS SQL 2005

Hello. I am trying to modify the SQL query below to show the Top 5 and Bottom 5 results. I have a country table. I want to display the top 5 countries in % compliance and the bottom 5 % compliance.

I tried several ways of using Top (5) but could not get it to work. Any suggestions?
SELECT     Regional_Location.Country, 100 * SUM(CASE WHEN pse.LastStateName = 'Install Verified' THEN 1 ELSE 0 END) / COUNT(*) AS '% Compliant'
FROM         v_GS_PatchStatusEx AS pse INNER JOIN
                      v_R_System ON pse.ResourceID = v_R_System.ResourceID INNER JOIN
                      Regional_Location ON v_R_System.AD_Site_Name0 = Regional_Location.AdSite INNER JOIN
                      v_ApplicableUpdatesSummaryEx ON pse.UpdateID = v_ApplicableUpdatesSummaryEx.UpdateID
WHERE     (v_ApplicableUpdatesSummaryEx.TimeAuthorized not like 'Null')
GROUP BY Regional_Location.Country

Open in new window

Microsoft SQL Server 2005

Avatar of undefined
Last Comment

8/22/2022 - Mon