T-SQL取n到m行数据
来源:互联网 发布:塔吊考试模拟考试软件 编辑:程序博客网 时间:2024/05/01 12:17
取n到m行
1.
select top m * from tablename where id not in (select top n id from tablename order by id asc/*|desc*/)
2.
select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入到临时表
set rowcount n --只取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 identity_col between n and m
6.SQL2005开始.可以使用row_number() over()生成行号
;with cte as
(
select id0=row_number() over(order by id),* from tablename
)
select * from cte where id0 between n to m
摘自CSDN。
- T-SQL取n到m行数据
- SQL 取n到m条记录
- MySQL、MS SQL、Oracle三种数据库查询M到N行数据
- SQL取m到n条数据;数据库分页
- SQL取n到m条记录的语句
- 取n到m行
- sql取每组前N行数据
- [5月7日的脚本] 删除前n列相同的表格的行的m-1行数据 (T-SQL)
- 取N到M中间的记录
- 取N到M的办法
- 取从M到N行
- 查询取n到m行
- 查询取n到m行
- SQL SERVER 取重复值和取某列第N大值得行数据的 SQL语句
- T行数据跟着N个数据
- 取sql表中n到m条记录的语句
- SQLite随机取n行数据
- SQLite随机取n行数据
- Hibernate HQL 分组求和查询
- XP系统Ghost后登录时自动注销的解决方法
- ARMA模型仿真改进及灰色理论的故障预测
- 动态列转行
- sql server 相关
- T-SQL取n到m行数据
- 探本溯源——什么是科学研究?什么是一流的科学研究?
- Poi Cell类型与数值对照
- T-SQL分割字符串--转自CSDN的树哥(Josy)
- PHP 遍历数组的方法汇总
- 断开网络dom4j无法解析有网络dtd的xml文件的解决办法
- 管中窥豹——科学、技术、工程之差异
- CRM系统开发经验谈
- 管中窥豹——应试教育与一流科学人才究竟有多远的差距