问题描述
我从一排数字中准备了字符串.当我使用 row_number
函数时,order by 子句不起作用
I preapare string from row of nubmers. When I use the row_number
function, the order by clause not working
结果 9876543211816141210864227242118151296336322824201612844540353025201510554484236302418126635649423528211477264564840322416881726354453627189"
result "9876543211816141210864227242118151296336322824201612844540353025201510554484236302418126635649423528211477264564840322416881726354453627189"
差异在哪里?
推荐答案
我希望这与 这个问题,总结一下当你使用变量连接时,例如
I expect this is related to this issue, in summary when you use variable concatenation, e.g.
结果取决于物理实现和内部访问路径.我目前正在努力在互联网上寻找基准测试,但我认为 SQL Server 中最快、最可靠的方法是使用 XML 扩展将行连接到列:
The results are dependant on physical implementation and internal access paths. I am currently struggling to find benchmark tests on the internet, but I think the fastest, reliable approach in SQL Server is to use XML extensions to concatenate rows to columns:
注意我还删除了对 master..spt_values
的引用并替换为表值构造函数 - 这只是添加了不必要的读取以生成从 1 到 9 的序列.
N.B. I have also removed the reference to master..spt_values
and replaced with a table value constructor - this just adds unnecessary reads to generate a sequence from 1 to 9.
如果您的序列需要更多数字,我仍然不会使用系统表,请使用 Iztik Ben-Gan 的堆叠 CTE 方法,如 这篇文章:
If you need more numbers for your sequence I would still not use system tables, use Iztik Ben-Gan's stacked CTE approach, as described in this article:
这篇关于TSQL USE ROW_NUMBER IN CTE,SELECT ORDER BY NOT WORKING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!