row_number限制与视图

发布于 2025-02-07 09:15:23 字数 593 浏览 3 评论 0原文

我正在测试一个简单的查询部分,该部分从视图而不是表运行。当我忽略Row_number线时,查询返回结果。有了这一行活动,我只会得到无效的结果。是否有一定的限制反对在某种程度上进行此类操作?

SELECT
    `VMC Savings`,
    ROW_NUMBER() OVER (ORDER BY `VMC Savings`) AS row_n
FROM v_vmc_summary

ROW_NUMBER代码的结果:

row_number的结果评论了:

I'm testing a simple query section that runs from a view instead of a table. When I leave out the ROW_NUMBER line, the query returns results. With this line active, I just get NULL results. Is there some restriction against doing these kinds of operations on a view?

SELECT
    `VMC Savings`,
    ROW_NUMBER() OVER (ORDER BY `VMC Savings`) AS row_n
FROM v_vmc_summary

Result with ROW_NUMBER code:
enter image description here

Result with ROW_NUMBER commented out:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃不饱 2025-02-14 09:15:23

评估每个记录的分区没有分区,并且是否存在零记录;空将替换每个值。

通过完整键的分区或过滤删除无效结果。

“按子句分区是ROW_NUMBER函数的可选部分,如果您不使用它,则结果集的所有记录都将被视为单个记录组或单个分区的一部分,然后应用排名函数。”

来源上述: https:/ /www.c-sharpcorner.com/blogs/Rownumber-function-with-with-by-clause-clause-in-sql-server1

但我相信它也适用于mysql ..

因为它将其视为一种单分区;无效,无效需要特殊处理...我认为存在问题。

我想如果您愿意为0,则可以合并(值为0)。

without a partition by every record is evaluated and if null exists; Null will replace every value.

Partition by the complete key or filter out null results.

"Partition by clause is an optional part of Row_Number function and if you don't use it all the records of the result-set will be considered as a part of single record group or a single partition and then ranking functions are applied."

above source: https://www.c-sharpcorner.com/blogs/rownumber-function-with-partition-by-clause-in-sql-server1

but I believe it applies to mysql as well..

Since it looks at it as a single partition; and NULL exists and null needs special handling... I think there in is the problem.

I suppose you could coalesce(value,0) if you are willing the nulls to be 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文