Wednesday, January 6, 2010

Rank order by using simple query

In SQL Server 2005, we can use RANK() to display rank order in the result set.
However, assume that we don't know that, we can use the simple query as the following:
SELECT COUNT(*) AS Rank, t1.EmployeeID, t1.EmployeeName
FROM Employee t1, Employee t2
WHERE t1.EmployeeID >= t2.EmployeeID
GROUP BY t1.EmployeeID, t1.EmployeeName

No comments:

Post a Comment

Oracle Query