我有多个应用程序,每个应用程序都有唯一的应用程序 ID,每个应用程序都有存储在表中的日志。我想知道如何计算日期差异,例如:
AppID Start Loggedon change
A1 08/07/2010 08/09/2010 Xchange
A1 08/07/2010 08/20/2010 Ychange
A1 08/07/2010 08/30/2010 Zchange
A2 07/07/2010 07/13/2010 Ychange
A3 09/07/2010 09/09/2010 Xchange
所以我想要价值观
Difference
2 (Difference between the application start date and 1st loggedon date)
11 (difference between 08/20 and 08/09, the prior row because AppID stayed the same)
10 (difference between 08/30 and 08/20, the prior row because AppID stayed the same)
6 (Difference between the application start date and 1st loggedon date)
2 (Difference between the application start date and 1st loggedon date)
希望我清楚。我怎样才能做到这一点,我尝试了 Ranking 和 Row_Number。但我可能在某个地方错了。我正在使用 SQL Server,但无法使用 LAG()