Home>

When writing a program today,Need to generate sql statements from start id to end id. This feature was not needed now, it is needed now.

How to write sql statements for querying the data between the first few and the first few in the database in sql server?

For example:how to write the SQL statement in the SQL server to query the data between the 10th and 30th in the database?

------solution--------------------

select top 20 * from table where id in (select top 30 id from table order by id) order by id desc

------solution--------------------

If there is a unique column, you can use ls

select identity (int, 1,1) id, * into temp from table

select * from temp where id between 10 and 30

------solution--------------------

select top 20 * from table where identification field is not in (select top 9 identification field from table)

------solution--------------------

1

select top 20 * from table

where id not in (select top 10 id from table order by id)

order by id

2-- should start from 11

select * from table where id between 11 and 30

  • Previous Detailed ARC memory management methods in iOS application development
  • Next In-depth analysis of function usage in golang programming