SQL返回第M条至第N条记录
SQL返回第M条至第N条记录,如何编写查询语句上面说法不太准确,应该是:SQL返回一个查找结果集中的第M条至第N条记录...
SQL返回第M条至第N条记录,如何编写查询语句
上面说法不太准确,应该是:SQL返回一个查找结果集中的第M条至第N条记录 展开
上面说法不太准确,应该是:SQL返回一个查找结果集中的第M条至第N条记录 展开
3个回答
展开全部
总结的查找从第N条到第M条记录,希望对你有帮助:
查找第n到m条记录:
(1)select top m * from tablename where id not in (select top n id from tablename)
此语句需要在表有主键类字段,此句里的为id
(2) select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入
set rowcount n
select * from 表变量 order by columnname desc
(3)select top n * from
(select top m * from tablename order by columnname) order by columnname desc
(4)如果tablename里没有其他identity列,那么:
select identity(int) id0,* into #temp from tablename
取n到m条的语句为:
select * from #temp where id0 >=n and id0 <= m
如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你 的 DB中间的select into/bulkcopy属性没有打开要先执行:
exec sp_dboption 你的DB名字,'select into/bulkcopy',true
(5).如果表里有identity属性,那么简单:
select * from tablename where identity col between n and m
查找第n到m条记录:
(1)select top m * from tablename where id not in (select top n id from tablename)
此语句需要在表有主键类字段,此句里的为id
(2) select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入
set rowcount n
select * from 表变量 order by columnname desc
(3)select top n * from
(select top m * from tablename order by columnname) order by columnname desc
(4)如果tablename里没有其他identity列,那么:
select identity(int) id0,* into #temp from tablename
取n到m条的语句为:
select * from #temp where id0 >=n and id0 <= m
如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你 的 DB中间的select into/bulkcopy属性没有打开要先执行:
exec sp_dboption 你的DB名字,'select into/bulkcopy',true
(5).如果表里有identity属性,那么简单:
select * from tablename where identity col between n and m
展开全部
取n到m条记录的语句
1.
select top m * from tablename where id not in (select top n id from tablename)
2.
select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入
set rowcount n
select * from 表变量 order by columnname desc
3.
select top n * from
(select top m * from tablename order by columnname) a
order by columnname desc
4.如果tablename里没有其他identity列,那么:
select identity(int) id0,* into #temp from tablename
取n到m条的语句为:
select * from #temp where id0 >=n and id0 <= m
如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开要先执行:
exec sp_dboption 你的DB名字,'select into/bulkcopy',true
5.如果表里有identity属性,那么简单:
select * from tablename where identitycol between n and m
1.
select top m * from tablename where id not in (select top n id from tablename)
2.
select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入
set rowcount n
select * from 表变量 order by columnname desc
3.
select top n * from
(select top m * from tablename order by columnname) a
order by columnname desc
4.如果tablename里没有其他identity列,那么:
select identity(int) id0,* into #temp from tablename
取n到m条的语句为:
select * from #temp where id0 >=n and id0 <= m
如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开要先执行:
exec sp_dboption 你的DB名字,'select into/bulkcopy',true
5.如果表里有identity属性,那么简单:
select * from tablename where identitycol between n and m
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select ROW_NUMBER() over (order by TA.id desc) as 'rowNumber' ,*
from 表A
先添加序号
然后
select *
(select ROW_NUMBER() over (order by TA.id desc) as 'rowNumber' ,*
from 表Am ) as 表B
表B.rowNumber between m and n
给分吧 你用这个可以做 数据库分页 很好使
from 表A
先添加序号
然后
select *
(select ROW_NUMBER() over (order by TA.id desc) as 'rowNumber' ,*
from 表Am ) as 表B
表B.rowNumber between m and n
给分吧 你用这个可以做 数据库分页 很好使
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询