title: Top 5 Employees from each dept with lowest attendance
body: <p>How do I find top 5 employees from each department with lowest attendance?</p>
  <p><strong>---Employee Table</strong></p>
  <p><img src="https://i.stack.imgur.com/AISy9.png" alt="EmployeeTable" /></p>
  <p><strong>--- Department Table</strong></p>
  <p><img src="https://i.stack.imgur.com/aNgSe.png" alt="DepartmentTable" /></p>
  <p><strong>--- Attendance Table</strong></p>
  <p><img src="https://i.stack.imgur.com/yFQZz.png" alt="AttendanceTable" /></p>
  <p>I tried in this way to find top 5 salary from each department but how to apply in this specially for attendance table with employee and department table how to find top 5 employees with lowest attendance please assist me in this regard with cte.</p>
  <p>Thanks</p>
  <pre><code>With ctetemp As
  (
      Select E.EmpId, E.Ename, E.Salary,D.Dname, 
             DENSE_RANK() OVER(PARTITION BY D.DeptId ORDER BY Salary desc) as rnw
      from EmployeeTbl AS E JOIN Departmet AS D
      ON   D.DeptId = e.Dept_Id_Emp
  )
  Select * from ctetemp
  where rnw IN (5)
  </code></pre>