我有一个查询为:被反复对每一个GRPSQL窗口函数:MAX(日)在PARTITION BY子句
select
location_id,
max(created) over (partition by location_id) as "created"
from
device
group by
location_id, created
order by
location_id
这将导致最大的日期。
21 2015-01-26T18:25:00.000Z
22 2015-10-18T13:21:32.000Z
22 2015-10-18T13:21:32.000Z
22 2015-10- 18T13:21:32.000Z
现在,如果我计算日期之间的差值:
select
location_id,
date(created),
max(date(created)) - min(date(created)) over (partition by location_id) as "created"
from
device
group by
location_id, created
order by
location_id
21 2015-01-26T0 0:00:0 00.000Z
22 2015-01-26T00:00:0 00.000Z
22 2015-03-12T00:00:45 00.000Z
22 2015-10-18T00:00:00.000Z 265
为什么我会得到第一个记录和第二个,然后第三个之间的区别?为什么不只是通过组重复最大 - 最小的差异?
希望我对这个问题很清楚。
哪个RDBMS是为了这个?请添加一个标签来指定您是使用'mysql','postgresql','sql-server','oracle'还是'db2' - 或者其他的东西。 –