Wednesday, December 8, 2010

Select Top 10% of rows - SQL Server 2008

Execute the following SQL Server T-SQL scripts in SSMS Query Editor to list the top 5 percent result set with ties and without ties:

USE AdventureWorks;



SELECT TOP ( 10 ) PERCENT WITH TIES Employee = FirstName + ' ' + Lastname,

e.Title,

Gender,

Rate

FROM HumanResources.Employee e

JOIN HumanResources.EmployeePayHistory eph

ON e.EmployeeID = eph.EmployeeID

JOIN Person.Contact c

ON c.ContactID = E.ContactID

ORDER BY Rate DESC;

GO

=====================================================================



SELECT TOP ( 10 ) PERCENT Employee = FirstName + ' ' + Lastname,

e.Title,

Gender,

Rate

FROM HumanResources.Employee e

JOIN HumanResources.EmployeePayHistory eph

ON e.EmployeeID = eph.EmployeeID

JOIN Person.Contact c

ON c.ContactID = E.ContactID

ORDER BY Rate DESC;