排名函数结构
我很了解排名函数的 DENSE_RANK() 函数及其工作。但我总是只写这个函数的名称,它隐式地完成它的工作,无法看到它是如何显式工作的,我喜欢看到它的结构,它使用 T_SQL 语言在这个函数中执行操作。请你帮我解决一下好吗?
I know the DENSE_RANK() function of the ranking function and its job well. But always I only write this function’s name and it do its job implicitly can cannot see how it work explicitly and I like to see its structure which do the operations within this function with T_SQL language. Would you please help me with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从执行计划中看到这一点。
示例代码
执行计划
描述
首先需要按 G、S 顺序对数据进行排序,因为没有适合使用的预排序索引。
然后有2个段迭代器。段迭代器具有“GROUP BY”属性。它们输出一个段列,指示当前行是否与前一行位于同一组中。
第一个段迭代器按分区列 G 分组并输出段列 Segment1004。
第二个段迭代器按 G,S 分组并输出 Segment1005 作为段列。
序列项目迭代器根据这些输入输出
dense_rank
值。如果Segment1004表明这是一个新的分区组,则输出1,否则将检查Segment1005的值,以决定是输出与上次相同的值还是先递增它。查看这篇文章保罗·怀特了解更多
You can see this from the execution plans.
Example Code
Execution Plan
Description
It first needs to sort the data in order G,S as there is no suitable index to use which is presorted.
Then there are 2 segment iterators. Segment iterators have a "GROUP BY" property. They output a segment column indicating whether the current row is in the same group as the previous one or not.
The first segment iterator Groups by the partitioning column G and outputs segment column Segment1004.
The second segment iterator Groups by G,S and outputs Segment1005 as the segment column.
The Sequence Project iterator outputs the
dense_rank
value based on these inputs. It will output 1 if Segment1004 indicates that this is a new partitioning group otherwise it will check the value of Segment1005 to know whether to output the same value as last time or to increment it first.See this article by Paul White for more