为了做到你想要的,你需要生成一个数字序列。也许你有一张桌子。如果没有,像下面这样:
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