1
我在格式數據蜂房邏輯得到分鐘時間,最大的時間和其他列
+---------------------+-------------------------+-------------------------+-----------+------+
| id | start time | end time | direction | name |
+---------------------+-------------------------+-------------------------+-----------+------+
| 9202340753368000000 | 2015-06-02 15:10:28.677 | 2015-06-02 15:32:22.677 | 3 | xyz |
| 9202340753368000000 | 2015-06-02 14:55:37.353 | 2015-06-02 15:12:18.84 | 1 | xyz |
+---------------------+-------------------------+-------------------------+-----------+------+
,我需要像最小啓動時間輸出,最大結束時間,方向值爲分鐘開始時間和名稱
+---------------------+-------------------------+------------------------+-----------+------+
| id | start time | end time | direction | name |
+---------------------+-------------------------+------------------------+-----------+------+
| 9202340753368000000 | 2015-06-02 14:55:37.353 | 2015-06-02 15:32:22.677| 1 | xyz |
+---------------------+-------------------------+------------------------+-----------+------+
我使用
select x.id, min(x.start_time) as mintime, max(x.end_time) maxtime , y.direction, y.name
from dir_samp x inner join (
select id, start_time, end_time, name, direction ,
rank() over (partition by id
order by start_time asc) as r
from dir_samp
) y on x.id = y.id where y.r = 1 group by x.id , y.direction, y.name
如果有任何其他更有效的邏輯已經試過?請提供。
感謝