If there is a t_user data table in this way, the table ID increases automatically, but the IDs in the data table are not guaranteed to be continuous. Write an SQL statement, query the data between the n-th record and the M-th record (M> N> 0, all smaller than the total number of records in the data table)
The idea is as follows:
- First, find the ID of the nth record and the nth record.
- Obtain the ID of the nth record whose ID is greater than the nth Record ID and smaller than the nth Record ID.
CodeThe decomposition is as follows:
- Obtain the ID of the nth record:Select max (ID) from t_user where ID in (select Top n id from t_user)
- Obtain the ID of the MTH record:Select max (ID) from t_user where ID in (select top m id from t_user)
The SQL statement is as follows:
Select * From t_user where ID> (select max (ID) from t_user where ID in (select Top n id from t_user) and ID <(select max (ID) from t_user where ID in (select top m id from t_user ));