我有以下示例数据
create Table #Temp(id int, Data1 varchar(10), Data2 bigint)
Insert Into #Temp
Values(1,'Value1',109040774),
(2,'Value2',10000006099758),
(3,'Value3',10000006099758),
(4,'Value1',14538),
(5,'Value2',10000006097458),
(6,'Value3',10000006097458),
(7,'Value1',4454834),
尝试根据Data1
选择新列,因此输出将为
id Data1 NewColumn
1 Value1 109040774
2 Value2 109040774
3 Value3 109040774
4 Value1 14538 --reset here because same value of Data1 (Value 1 started repeating)
5 Value2 14538
6 Value3 14538
7 Value1 4454834 --reset here because same value of Data1 (Value 1 started repeating)
我试图使用下面的内容,但不是我之后的内容
SELECT id, Data1,
FIRST_VALUE(Data2) OVER (Partition by Data1 ORDER BY Id ASC) AS NewCol
FROM #Temp
Order By Id
感谢任何帮助
答案 0 :(得分:2)
我的想法是假设一个特殊的pointRange: 1
定义了一个新组:
value1
的数量。value1
。因此:
first_value()