title: Getting 5 worst of each group in SQL Server
body: <p>I have a code in SQL where I am trying to get the top 5 worst for each function. I would like it to just grab the 5 worst for each group not the 5 worst overall. The code is as follows:</p>
  
  <pre><code>SELECT TOP (100) PERCENT Job_Function, CMX_DSC_TE, MGR_ANW_CD_Num - DES_LVL_NR_Num AS JSC_Gap
  FROM  dbo.AC_GLN_Project_JSC
  ORDER BY Job_Function, JSC_Gap
  </code></pre>
  
  <p>The table looks like: (This is a smaller version)</p>
  
  <pre><code>AG  Air Operations Tools and Equipment Knowledge    -2
  AG  Capacity Planning Knowledge                     -1
  AG  Conducts Research                                 -3
  AG  Equipment Repair Management                     -4
  AG    
  AG  Equipment Repair Management                     -3
  AG  Facilities, Equipment, and Grounds Maintenance  -3
  AG  Facilities, Equipment, and Grounds Maintenance  -2
  AG  Instructional Design Knowledge                      -2
  AG  Plans Flight Operations                     -1
  AG  Statistical Analysis    -2
  AG  Troubleshoots Aircraft Failures            0
  AG  Vendor/Supplier Management                       -3
  AUTOMOTIVE  Automotive Engineering Knowledge    -1
  AUTOMOTIVE  Budget Management   -3
  AUTOMOTIVE  Labor Relations Knowledge   -3
  AUTOMOTIVE  Mechanical Knowledge    -3
  AUTOMOTIVE  Mechanical Knowledge    -3
  AUTOMOTIVE  Mechanical Knowledge    -2
  AUTOMOTIVE  Applies Marketing Knowledge     0
  AUTOMOTIVE  Applies Service, Product, and Customer Technology Knowledge -3
  </code></pre>
  
  <p>I Need it to look like: </p>
  
  <pre><code>AG Equipment Repair Management -4
  AG Facilities, Equipment, and Grounds Maintenance -3
  AG Conducts Research -3
  AG VEndor Supply Management - 3
  AG Air Operations Tools and Equipment Knowledge -2
  AUTO Labor Relations Knowledge -3
  AUTO Budget Management -3
  AUTO Mechanical Knowledge -3
  AUTO Applies Service, Product, and Customer Technology Knowledge    -3
  AUTO Automotive Engineering Knowledge -1
  </code></pre>
  
  <p>Even if the same CMX_DSC_TE repeats the exact same score I only need one of them listed.</p>