TSQL-查找 SQL Server 中多条记录的天数差异
SQL Server 2008 R2中是否可以找到不同记录的天数差异?
SELECT OrderDate FROM OrdersTbl WHERE SKU='AA0000' ORDER BY ORDERDATE DESC
OrderDate
-----------------------
2009-12-03 00:00:00.000
2009-04-03 00:00:00.000
2008-02-22 00:00:00.000
2008-02-21 00:00:00.000
2007-02-18 00:00:00.000
2007-01-27 00:00:00.000
2006-10-13 00:00:00.000
我想要一种方法来获取每个订单日期之间有多少天,以便我可以找到平均频率。提前致谢。
Is it possible to find the difference of days of different records in SQL Server 2008 R2?
SELECT OrderDate FROM OrdersTbl WHERE SKU='AA0000' ORDER BY ORDERDATE DESC
OrderDate
-----------------------
2009-12-03 00:00:00.000
2009-04-03 00:00:00.000
2008-02-22 00:00:00.000
2008-02-21 00:00:00.000
2007-02-18 00:00:00.000
2007-01-27 00:00:00.000
2006-10-13 00:00:00.000
I would like a way to get how many days in between there are for each order date so that I could find the average frequency. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用公用表表达式和 ROW_NUMBER 来完成此操作:
You can do it with a common table expression and ROW_NUMBER:
糟糕的是 SQL Server 中没有 LEAD/LAG 支持:
Sucks there's no LEAD/LAG support in SQL Server: