爲了做到你想要的,你需要生成一個數字序列。也許你有一張桌子。如果沒有,像下面這樣:
select dstart + interval n.num days
from (select d1*10+d2 as num
from (select 0 as d union all select 1 union all select 2 union all
select 3 union all select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9
) d1 cross join
(select 0 as d union all select 1 union all select 2 union all
select 3 union all select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9
) d2
) n join
(select date('2012-01-02') as dend, date('2012-01-01') dstart
on dstart + interval n.num days <= dend
(這不是測試,所以它可能有語法錯誤。)
澄清:你想通過日期時間的列表,並獲得每個之間的差異一個(即1和2,2和3等)? – pzirkind
不,我只有兩個時間戳timestamp1(2012-01-01 ...)和timestamp2(2012-01-09 ...)。結果應該是1月1日至9日的日期以及比例小時/分鐘/秒。 – Thomas1703
啊,請在問題中發佈所需的輸出,以便我們可以更好地爲您提供幫助 – pzirkind