我想添加一个包含每个组中第一个的列。获取SQL Server中每个组中的顶级ID
样品:
Product ID
Orange 1
Orange 2
Orange 3
Orange 4
Apple 5
Apple 6
Apple 7
Grapes 8
Grapes 9
所需的输出:
Product ID
Orange 1
Orange 1
Orange 1
Orange 1
Apple 5
Apple 5
Apple 5
Grapes 8
Grapes 8
Apple:5,5,7? ,有点混乱。 – Japongskie
'MIN(ID)OVER(PARTITION BY Product)'会做到这一点。 [SQL小提琴](http://sqlfiddle.com/#!6/9eecb7/3867/0) –