一个简单的问题, 谁帮写一下,sql语句(从一张表中取第10条到25条记录)。(50分)

  • 主题发起人 主题发起人 txjtxj
  • 开始时间 开始时间
T

txjtxj

Unregistered / Unconfirmed
GUEST, unregistred user!
一个简单的问题, 谁帮写一下,sql语句(从一张表中取第10条到25条记录)。
 
oracle:
select * from tablename
where rownum between 10 and 25
 
不好意思,我没说完,我用的是mssql
 
你的表(TableName)中一定有一个主关键字(排序字段),假设为 KeyId

select Top 15 * from (select Top 25 * from TableName order by KeyId Asc) order by KeyId Desc
 
select * from (select rownum id,pjid from piaoju where rownum<55) where id>15 and id<25
 
同意 finnz
 
如果主关键字中间断开了,可不可以呢。
比如:10、11、12、14.....
中间没有13.或没有14.
 
select Top 15 * from (select Top 25 * from TableName order by KeyId Asc) order by KeyId Desc
这句话我试了,但在order 附近有错误.
 
改为
select Top 15 *
from
(select Top 25 * from TableName order by KeyId Asc) as a
order by KeyId Desc 即可。若返回字段较多也可用如下语句:
select * from TableName
where KeyId in (select top 25 KeyId from TableName )
and KeyId not in (select top 9 KeyId from TableName )
 
照llh_lily的作吧
 
select Top 15 *
from
(select Top 25 * from TableName order by KeyId Asc) as a
order by KeyId Desc
这句话写的不对,返回的值不正确
 
to txjtxj:
是不是记录数不对,还是记录的排序方式不对,若记录数不对则换以下的语句:
select Top 16 *
from (select Top 25 * from TableName) as a
order by KeyId Desc
若是排序方式不满意,那你还是用这条语句:
select * from TableName
where KeyId in (select top 25 KeyId from TableName )
and KeyId not in (select top 9 KeyId from TableName )
 
select Top 16 *
from (select Top 25 * from TableName) as a
order by KeyId Desc
这句话返回的值根本就不对。
 
select * from
(
select Top 15 * from
(
select Top 25 * from TableName order by KeyId Asc
) order by KeyId Desc
)order by KeyId
 
To T金花:
请指明是怎么个不对?[?]
 
后退
顶部