The following describes how to write SQL statements for mysql/Oracle/mssql to retrieve the first few pieces of data. If you need them, refer to them.
If you use this statement in ms sqlserver:
The Code is as follows: |
Copy code |
Select top 2 * from test01 |
Oracle statement:
The Code is as follows: |
Copy code |
Select * from (select rownum r, * from test) ttwhere tt. r> 50 and tt. r <= 100; |
(It is best to use PLSQL cursor to solve this problem)
In DB2:
The Code is as follows: |
Copy code |
Select * from payment fetch first 5 row only -- query the first 5 Records |
MSSQL
If you use this statement in ms sqlserver:
The Code is as follows: |
Copy code |
Select top 2 * from test01 |
Only the first two records are displayed,
MYSQL can use limit.
The Code is as follows: |
Copy code |
Select * from your_table where... limit 2;
|
One msssql instance
1. Use ms SQL Server 2008;
2. The database content is as follows: Zhang San mathematics 98 Li Si mathematics 95 Wang Wu mathematics 90 Zhao Liu English 100 Zhang San English 99 Li Si English 69
3. results to be queried: the first two of each course
The Code is as follows: |
Copy code |
Select. xingming,. kemu,. fenshu from xuexi a where. fenshu in (SELECT top 2 fenshu FROM xuexi WHERE xingming =. xingming and kemu =. kemu order by fenshu desc) |