SQL 最后一天在 moth select 中
我有下表,基本上是每日交易的摘要,并且每晚加载。
+++++++++++++++++++++++
+ DateCreated + Sale +
+++++++++++++++++++++++
+ 20100101 + 1000 +
+ 20100131 + 2000 +
+ 20100210 + 2000 +
+ 20100331 + 4000 +
+++++++++++++++++++++++
我需要按月显示销售情况,但仅显示每个月的最后一天。
例如,
JAN 2000
FEB 0
MAR 4000
我可能可以在我的选择中使用 CASE 来完成此操作,但这有效吗?这是 SQL Server 2000。
I have the following table which is basically the summary of daily transactions and is loaded nightly.
+++++++++++++++++++++++
+ DateCreated + Sale +
+++++++++++++++++++++++
+ 20100101 + 1000 +
+ 20100131 + 2000 +
+ 20100210 + 2000 +
+ 20100331 + 4000 +
+++++++++++++++++++++++
I need to display the sale by month, but only for the last day in each month.
eg
JAN 2000
FEB 0
MAR 4000
I could probably accomplish this with CASE in my select, but is this efficient? This is SQL Server 2000.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的问答解决方案是构造一个日期,即下个月的第一天,然后减去一天。
My Q&D solution to this has been to construct a date that's the first day of the next month, then subtract a day.
你可以这样做,但它不会显示丢失数据的 0:
You could do something like this, but it will not show 0 for missing data:
我有一个日历表,只是添加了一个“IsLastDayOfMonth”列,设置每个月的最后一天。然后将其加入到我的查询中,仅按“IsLastDayOfMonth”进行过滤,并且有效。
I had a calendar table, just added a "IsLastDayOfMonth" column, set the last day of each month. Then joined that to my query, filtering by "IsLastDayOfMonth" only and that worked.