3 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊
您還可以使用LAG分析功能來(lái)獲得所需結(jié)果,如下所示:
假設(shè)下面是您的輸入表:
id account_number account_date
1 1001 9/10/2011
2 2001 9/1/2011
3 2001 9/3/2011
4 1001 9/12/2011
5 3001 9/18/2011
6 1001 9/20/2011
select id,account_number,account_date,
datediff(day,lag(account_date,1) over (partition by account_number order by account_date asc),account_date)
as day_diffrence
from yourtable;
這是您的輸出:
id account_number account_date day_diffrence
1 1001 9/10/2011 NULL
4 1001 9/12/2011 2
6 1001 9/20/2011 8
2 2001 9/1/2011 NULL
3 2001 9/3/2011 2
5 3001 9/18/2011 NULL
- 3 回答
- 0 關(guān)注
- 649 瀏覽
添加回答
舉報(bào)