如何限定接收第30条到50条返回的记录,我就剩25分了(25分)

  • 主题发起人 主题发起人 gz85521734
  • 开始时间 开始时间
G

gz85521734

Unregistered / Unconfirmed
GUEST, unregistred user!
譬如一个查询语句,select id,name where sex='F'
我需要只接收第30条到50条记录,如何做到?
注意!因为只接收sex为F的记录,所以是不能用id between xxx来限定的
 
什么数据库?
 
1.sqlserver
2.mysql
 
SQL Server下可通过临时表来达到

Select Identity(int,1,1) as tmp,
id,name
Into #temp
From Table1
where sex='F'
Go

Select id,name
From #temp
Where tmp>=30 and tmp<=50
Go

 
要是两个用户同时查询呢?用临时表不是一个好方法
 
把它做成一个存储过程,在存储过程中用临时表,就不会发生用户突冲了
 
QuickSilver,你的方法对于2.mysql无效,因为mysql没有storedprocedure。
当然,sql-server里边是可以得
 
运用关键字TOP:
select top 20 id,name from tablename where id not in (select top 30 id from tablename where sex='F' order by id) and sex='F' order by id
 
hzred, mysql不支持子查询,所以你的答案也没法用 :(
 
后退
顶部