行号/排名“特定分区”

发布于 2025-02-12 18:54:21 字数 454 浏览 1 评论 0原文

桌子是这个

这是错误的row_number,我想计算它以便按真实分组日期几周(从星期一到周日),即 1对于前4行,2行从5到8,为9到13的行,等等。也许这可以通过等级解决,但是请注意,所需的列并不总是取决于Year_week的更改。结果表将是:

The table is this
enter image description here

The row_number in this is wrong, I want to to compute it in order to group the dates by real weeks (from monday to sunday), i.e.
1 for the first 4 rows, 2 for rows from 5 to 8, 3 for rows from 9 to 13 and so on. Maybe this can be solve with rank, but notice the desired column not always is determined by the change in year_week. The resulting table would be:
enter image description here

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

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

发布评论

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

评论(1

尾戒 2025-02-19 18:54:21

只是为了结束答案...
搜索后,我发现此问题可以通过函数conditdital_change_event()解决,这并非在所有SQL lenguages中实现,而是可以被解释的。检查有关更多信息。

Just for close the answer...
After some searching I found this problem can ve solve with the function CONDITIONAL_CHANGE_EVENT(), this is not implemented in all SQL lenguages, but can be explicited. Check Is there any alternative to Vertica's conditional_true_event in RedShift? for more information.

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