SQL Server:限制填充零值直至使用特定文本

发布于 2025-01-26 14:53:40 字数 1054 浏览 1 评论 0原文

我有一个cte,我在第100行之前通过使用以下脚本在第100行之前将零值填充,

SELECT [YearMonth],grp,
CASE WHEN grp>grp 
     THEN (FIRST_VALUE([Value 1]) over (partition by grp order by [YearMonth]))

问题是我希望“最新”之后的行是无效的,但我不希望删除这些行。我需要显示其他列中的值。我会感谢任何帮助。

编辑

straw

年度值1
2021-010.9575
2021-02NULL
2021-03NEULL
2021-04null
2021-05NULL
2021-060.9875

预期台式

年度
strongstrong
< //
2021-030.9575
2021-040.9575
2021-050.9575
2021-060.9875

I have a CTE on which i am filling null values with the previous value before row 100 available by using the following script

SELECT [YearMonth],grp,
CASE WHEN grp>grp 
     THEN (FIRST_VALUE([Value 1]) over (partition by grp order by [YearMonth]))

The problem is that i want the rows after the "Latest" to be null but i dont want these rows to be deleted cause there are values in other columns which i need to show. I would appreciate of any help.

EDIT

Current Table

YearMonthValue 1
2021-010.9575
2021-02NULL
2021-03NULL
2021-04NULL
2021-05NULL
2021-060.9875

Expected table

YearMonthValue 2
2021-010.9575
2021-020.9575
2021-030.9575
2021-040.9575
2021-050.9575
2021-060.9875

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文