0
我有一個表如何獲得敏時間和下一步從同一個表敏時間在SQL Server
create table temp1
(
GroupId int,
DateCol Date,
ValueCol int,
)
insert into temp1 values(1,'2016-1-1',10);
insert into temp1 values(1,'2017-1-1',20);
insert into temp1 values(1,'2018-1-1',30);
insert into temp1 values(2,'2016-5-1',101);
insert into temp1 values(2,'2017-5-1',102);
insert into temp1 values(2,'2018-5-1',103);
我希望得到一個日期範圍(min到旁邊分鐘)通過的GroupId列分組:
ValueCol DateCol DateColNextToMin
111 (min Date) (next to Min Date)
GroupId ValueCol DateCol DateColNextToMin
1 10 2016-1-1 2017-1-1
2 101 2016-5-1 2017-5-1
我該怎麼做?
我就先徹底窗口功能,支點等,但似乎沒有這樣的優雅解決方案。
請出示一些示例數據,預期產出,一些DML到瑞普問題 – TheGameiswar
「雅」是在旁觀者的眼睛。你在這裏有什麼標準? –