一个关于 row_number()的疑问
-- 使用row_number直接获取数据,效率很低,需要1秒以上才能返回数据
select tb,pk,c_id,s_type,refresh
,row_number() over(order by s_type desc) as rowid
from caigou_2017_query.dbo.query q with (nolock)
inner join (select dbid,tbid,pkid from caigou_2017_triggers.dbo.tr_content with (nolock) where contains(content,'"分析测试"')) b on q.pk=b.pkid and q.tb=b.tbid
where db=15 and tb=1682105033
--不使用row_number测试,效率很高
select tb,pk,c_id,s_type,refresh
--,row_number() over(order by s_type desc) as rowid
from caigou_2017_query.dbo.query q with (nolock)
inner join (select dbid,tbid,pkid from caigou_2017_triggers.dbo.tr_content with (nolock) where contains(content,'"分析测试"')) b on q.pk=b.pkid and q.tb=b.tbid
where db=15 and tb=1682105033
-- 对子集进行row_number,效率和使用row_number一样
select *
--,row_number() over(order by s_type desc) as rowid
from (
select tb,pk,c_id,s_type,refresh
from caigou_2017_query.dbo.query q with (nolock)
inner join (select dbid,tbid,pkid from caigou_2017_triggers.dbo.tr_content with (nolock) where contains(content,'"分析测试"')) b on q.pk=b.pkid and q.tb=b.tbid
where db=15 and tb=1682105033
) a
-- 使用临时表,然后row_number,效率和没有使用row_number的指令一样
select tb,pk,c_id,s_type,refresh
into #tb
--,row_number() over(order by s_type desc) as rowid
from caigou_2017_query.dbo.query q with (nolock)
inner join (select dbid,tbid,pkid from caigou_2017_triggers.dbo.tr_content with (nolock) where contains(content,'"分析测试"')) b on q.pk=b.pkid and q.tb=b.tbid
where db=15 and tb=1682105033
select *
,row_number() over(order by s_type desc) as rowid
from #tb
drop table #tb
问,row_number是什么机制运行的?如果将row_number写到如上的命令是,不去影响查询效率
...全文
相关推荐
SQL Server 分页编号的另一种方式【推荐】
首先,ROW_NUMBER()函数是SQL Server中用于生成序列号或行号的标准方法。它基于指定的排序列(例如`ORDER BY Id DESC`),为每一行分配一个唯一的整数。
Oracle数据库分页的集中方法(三种方法)
ROW_NUMBER()函数的分页:Oracle 12c开始引入了ROW_NUMBER()窗口函数,它可以为查询结果集的每一行生成一个唯一的行号,不受ROWNUM的限制,可以方便地进行分页。
Oracle数字类型number自增的实现代码
- `ROW_NUMBER()`:在分析函数中,`ROW_NUMBER()`可以生成按指定顺序排列的行号,与`ROWNUM`类似,但更灵活,可以结合`OVER()`子句进行分组或分区计算。
ROW_NUMBER()函数
* 实现数据的排序和过滤ROW_NUMBER() 函数是一个非常有用的功能,它可以帮助我们快速地对数据进行排序和分页,从而提高查询效率。
深入探讨:oracle中row_number() over()分析函数用法
`row_number()`函数的一个重要应用场景是在分页查询中。


疑难问题
