我想要这个数字' 1000'仅出现一次,然后' 0'对于剩下的记录,直到下个月出现,也可以是一个案例类型语句?
我正在使用SQL,我希望这个数字“ 1000”每月出现一次。我有一个记录集,每个月的第一个出现多次。我希望剩下的记录仅出现一次“ 1000”,然后出现“ 0”,直到下个月出现为止。我想要以下请求 - 也许是一个案例类型语句/订单选择?我正在使用SQL Server 2018 @@ SQLServer。请参阅下面的表,以了解我希望数据出现的方式。
非常感谢:)
日期 | 金额 |
---|---|
01/01/2022 | 1000 |
01/01/2022 | 0 |
01/01/2022 | 0 |
01/02/2022 | 1000 |
01/02/2022 | 0 |
01/03/2022 | 01/02/2022 0 |
01/01 / | 1000 |
01/01/ 01/01/01/01/ 03/2022 | 0 |
I am using SQL and I would like this number '1000' to appear once per month. I have a record set which has the first of every month appearing multiple times. I would like the number '1000' to appear once only and then '0' for the remaining records until the next month appears. I would like the below please- maybe a case type statement/order parition by? I am using SQL Server 2018 @@SQLSERVER. Please see table below of how i would like the data to appear.
Many Thanks :)
Date | Amount |
---|---|
01/01/2022 | 1000 |
01/01/2022 | 0 |
01/01/2022 | 0 |
01/02/2022 | 1000 |
01/02/2022 | 0 |
01/02/2022 | 0 |
01/03/2022 | 1000 |
01/03/2022 | 0 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决问题的解决方案:
工作示例:
Solution for your problem:
Working Example: DB<>Fiddle Link
只有您可以使用 row_number 的日期列表和条件表达式任意分配每个月的一排值1000
Given just a list of dates you could use row_number and a conditional expression to arbitrarily assign one row of each month a value of 1000