Collection of SQL statement aggregation and other problems
For example, a data table contains 20 data records.
Read the first five data records
Select top 5 * from Table order by id desc
5 Data records after reading the first 5 data records
(That is, to query the first 10 records, take the last 5 Records)
Select top 5 * from table where
Id not in (select top 5 id from table)
========================================================== ========================================================== ===
Select top 11 * FROM (
SELECT ROW_NUMBER () OVER (order by StuID) AS RowNumber ,*
FROM StuInfo) t
WHERE RowNumber> = 10
Suppose StuID is the primary key "student ID" of the StuInfo table ". First sort by student ID, generate a row number, and then return the first 11 records with the row number> = 10, that is, the row number is 10 ~ 11 records of 20.
========================================================== ====================================
Select top 10 * from [table_name] where id in (select top 20 id from [table_name] order by id desc) order by id asc
As shown in this figure, there are 11 to 20 data records.