T-SQL备忘(4):分页

set statistics io on
set statistics time on
--SQL Server 2012分页方式
select * from Production.Product
order by ProductID offset 20 row fetch next 10 rows only
--SQL Server 05/08分页方式
go
with cte as
(
 select row_number() over(order by productid) as rowNum,* from production.product
)
select * from cte where rowNum>20 and rowNum<=30
--or
select * from (select row_number() over(order by productid) as rowNum,* from production.product) cte
where rowNum>20 and rowNum<=30

--通用方式
select top 10 * from Production.Product where ProductID not in
(
   select top 20 ProductID from Production.Product order by ProductID
) order by ProductID 

select top 10 * from Production.Product where ProductID>
(
 select max(ProductID) from (select top 20 ProductID from Production.Product order by ProductID) as temp
) order by ProductID

  

时间: 2025-01-04 14:58:35

T-SQL备忘(4):分页的相关文章

Postgresql,常用sql备忘

1.查看所有表的名称 Postgresql,greeplum,如果数据库在几千里以外,数据量巨大,网速不好,使用pgadmin客户端,那么你大部分时间都要浪费在等在中... 使用pgadmin的query是个不错的选择,但是,怎么才能知道表名呢,这丫真没mysql好用—— SELECT tablename FROM pg_tables where tablename not like 'gp%' and tablename not like 'gp%' and tablename not lik

一些性能查询的SQL 备忘

--检查数据库的等待事件 from v$session_waitwhere event not like 'SQL%' and event not like 'rdbms%' --找出系统中耗时的操作select b.username username,a.disk_reads reads,       a.executions exec,a.disk_reads/decode(a.executions,0,1,a.executions)           rds_exec_ratio,   

数据统计SQL备忘

1.统计9月注册角色首次充值时的游戏时长分布(分钟,人数),单位:分钟 SELECT sub.minutes,        Count(roleId) AS count FROM   (SELECT pr.roleId,                Timestampdiff(MINUTE, Max(player_login.logTime), pr.logTime)                + Ifnull(Max(player_logout.totalOnlineMins), 0)

Mysql又一次整理笔记--woods备忘

==============================SQL备忘 CRUD 查询 多表 事件等=============================== -------------------------------------------------------------------------------------------------- 一.数据库 1.创建数据库 create database [if not exists] db_name [character set

Mysql重新整理笔记--woods备忘

==============================SQL备忘 CRUD 查询 多表 事件等=============================== -------------------------------------------------------------------------------------------------- 一.数据库 1.创建数据库 create database [if not exists] db_name [character set

SQL注入备忘单

Find and exploit SQL Injections with free Netsparker SQL Injection Scanner SQL Injection Cheat Sheet, Document Version 1.4 About SQL Injection Cheat Sheet Currently only for MySQL and Microsoft SQL Server, some ORACLE and some PostgreSQL. Most of sam

SQL Server -- 自定义函数(学习总结,备忘)

SQL Server自定义函数,以前只在书上看过,没有动手去敲一敲,今天刚好接触到,看了几篇博文学习了下.做好备忘很重要!! (@[email protected])Y Learn from:http://www.cnblogs.com/lideng/archive/2013/04/15/3022418.html 自定义函数分为:标量值函数或表值函数两种. 标量值函数:如果 RETURNS 子句指定一种标量数据类型,则函数为标量值函数. 表值函数:如果 RETURNS 子句指定 TABLE,则函

工作中常用SQL 查询语句备忘

--当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列.select (case when a>b then a else b end ), (case when b>c then b esle c end) from table_name --求和查询 create table #tmp(rq varchar(10), shengfu nchar(1)) insert into #tmp values('2005-05-09','胜') insert into #tm

Phalcon 知识点备忘

phalcon 毕竟无法看到源代码,有些小设置还是需要实践记忆. 一.如何调用config.php里面的配置 很多时候,我们习惯将全局的配置参数放入主配置文件中,比如分页数.比如appkey之类. 'params' => array(  //加入config.php中,那controller中如何调用呢 'limit' => 10, ) 想要在controller中调用,可以通过services.php $di->set('main_config', $config); //将配置文件作