September 19, 2006 at 5:18 am
hi
select top 5 salaired employee
thanxs
September 19, 2006 at 5:55 am
SELECT TOP 5 * FROM dbo.Employee ORDER BY Salary_Col DESC
Prasad Bhogadi
www.inforaise.com
September 19, 2006 at 6:37 am
You can use also something like this:
SELECT TOP 5 MAX(salary_col) AS MaxSalary, Employee_ID
FROM employee_salaray
GROUP BY employee_id
ORDER BY MAX(Salary_Col) DESC
September 19, 2006 at 7:02 am
Do you have a table where the employees have more than one salary???
Where do I send my resume .
I would seriously consider query one unless you have a very special design!!
September 19, 2006 at 7:53 am
I think there can be employee with different salary but they would have different effectivity dates. Going along the lines here is the query that gets looks at the employee's most current pay rate and gets the top 5. You can exclude "InActive" employees by adding a where clause.
Select Top 5 EmployeeSalaray.EmployeeID,EmployeeSalaray.Salary,EmployeeSalaray.EffectiveDate
from EmployeeSalaray INNER JOIN
(Select EmployeeID,Max(EffectiveDate) as MaxEffectiveDate
from EmployeeSalaray
group by EmployeeID) MaxSal on EmployeeSalaray.EmployeeID = MaxSal.EmployeeID
and EmployeeSalaray.EffectiveDate = MaxSal.MaxEffectiveDate
order by EmployeeSalaray.Salary
Thanks
Sreejith
September 19, 2006 at 7:59 am
Your solution makes sense and depending on the modelling of the database the best required solution can be put to use.
Thx
Prasad Bhogadi
www.inforaise.com
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply