ROW_NUMBER 个新列
是否可以按 row_number 内的新列进行排序? 我想做这样的事情:
select text1 + text2 as NEW_TEXT, row_number over (order by NEW_TEXT) from table
但是这样的排序不起作用(我得到随机结果)。
Is it possible to order by a new column inside row_number?
I would like to do something like this:
select text1 + text2 as NEW_TEXT, row_number over (order by NEW_TEXT) from table
but such sorting doesn't work (I get random results).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须重复表达式
text1 + text2
或分步执行(foo 可能是这里的 CTE)
You have to repeat the expression
text1 + text2
Or do it in steps (foo could be a CTE here)
另一种选择是将初始结果包装在子选择中,并在此子选择上应用
ROW_NUMBER
。SQL语句
测试数据
Another option would be to wrap your initial results in a subselect and apply the
ROW_NUMBER
on this subselect.SQL Statement
Test Data
您可以使用子查询来完成此操作,如下所示:
You can do it using sub query like this way :