Practice Activity: How to retrieve the second row from a dataset in Microsoft SQL Server


How can you retrieve not the highest value but the second highest value? My SQL Server Udemy courses are: 70-461 70-761 Querying Microsoft SQL Server with T-SQL: 98-364: Database Fundamentals Microsoft SQL Server: 70-462 SQL Server Database Administration DBA: Microsoft SQL Server Reporting Services SSRS: SQL Server Integration Services SSIS: SQL Server Analysis Services SSAS: Microsoft Power Pivot Excel and SSAS Tabular DAX model: ---- In this practice activity youll learn how to retrieve the second row from a dataset in Microsoft SQL Server.
This is an important skill for data analysts and programmers and well take you through the steps step-by-step. If youre new to Microsoft SQL Server or need to learn how to retrieve data from a dataset then this practice activity is for you! Ill teach you the basics of retrieving data from a dataset in Microsoft SQL Server and by the end youll be ready to go out and use this skill in your work! It is easy to retrieve the highest value - just use MAX.
But how can you get the second highest value or the Nth value? If you want to do this as a Practice Activity then the starting code is as follows: DROP TABLE IF EXISTS tblHouseprices GO CREATE TABLE tblHousePrices PriceDate date NOT NULL Region varchar20 NOT NULL Price int NOT NULL ON PRIMARY GO INSERT INTO tblHousePrices VALUES 2024-06-01 Greater Manchester 346251 2024-07-01 East Midlands 312289 2024-07-01 West Midlands 365274 2024-08-01 East Midlands 328072 2024-08-01 Greater Manchester 353617 2024-09-01 East Midlands 339697 2024-09-01 West Midlands 370206 2024-09-01 Greater Manchester 358902 2024-10-01 West Midlands 376596 2024-10-01 Greater Manchester 357744 2024-11-01 West Midlands 371699 ---- Links to my website are: 70-461 70-761 Querying Microsoft SQL Server with T-SQL: 98-364: Database Fundamentals Microsoft SQL Server: SQL Server Essential in an Hour: 70-462 SQL Server Database Administration DBA: DP-300: Administering Relational Databases: Microsoft SQL Server Reporting Services SSRS: SQL Server Integration Services SSIS: SQL Server Analysis Services SSAS: Microsoft Power Pivot Excel and SSAS Tabular DAX model: 1Z0-071 Oracle SQL Developer certified associate: SQL for Microsoft Access: DP-900: Microsoft Azure Data Fundamentals: --- You can use either RANK or ROW_NUMBER to number each of the rows and then use a WITH to temporarily save it and then use a WHERE on the saved data.

Источник: rutube.ru

Сообщение от Commenton: Необходимо стартовать сессию