DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to SELECT TOP items with TIES?

Execute the following SQL Server T-SQL script in Management Studio Query Editor to SELECT the TOP hourly rate employees with TIES:

-- T-SQL TOP function with ties usage

USE AdventureWorks

GO

 

SELECT   TOP ( 5 ) PERCENT WITH TIES JobTitle = Title,

                                     Department = d.Name,

                                     Gender,

                                     HourlyRate = Rate

FROM     HumanResources.Employee e

         INNER JOIN HumanResources.EmployeeDepartmentHistory edh           

           ON e.EmployeeID = edh.EmployeeID AND EndDate is NULL

         INNER JOIN HumanResources.Department d

           ON edh.DepartmentID = d.DepartmentID

         INNER JOIN HumanResources.EmployeePayHistory eph

           ON eph.EmployeeID = e.EmployeeID

ORDER BY Rate DESC

 

 

JobTitle Department Gender HourlyRate
Chief Executive Officer Executive M 125.5
Vice President of Production Production M 84.1346
Vice President of Sales Sales M 72.1154
Vice President of Engineering Engineering F 63.4615
Chief Financial Officer Executive F 60.0962
Research and Development Manager Research and Development M 50.4808
Information Services Manager Information Services F 50.4808
Chief Financial Officer Executive F 48.5577
North American Sales Manager Sales M 48.101
European Sales Manager Sales F 48.101
Pacific Sales Manager Sales M 48.101
Engineering Manager Engineering M 43.2692
Finance Manager Finance F 43.2692
Research and Development Manager Research and Development M 42.4808
Research and Development Engineer Research and Development F 40.8654
Research and Development Engineer Research and Development F 40.8654

 

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE