Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我用 dateadd() 按周对数据进行分组,但我想按月分组。我有这个有趣的小 dateadd 函数。
DATEADD(day, - (1 * DATEPART(dw, Orders.OrderDate - 1)) + 1, CONVERT (date, Orders.OrderDate, 103))
所以我们从当前日期减去一周 - 在我看来就像将日期部分更改为月份并从中减去 1 一样简单,但是,这给了我一些非常古怪的结果如何修改它以减去月份几周?
所以你基本上已经尝试过了:
DATEADD(day, - (1 * MONTH(dw, Orders.OrderDate - 1)) + 1, CONVERT (date, Orders.OrderDate, 103))