如何在SQL中向Query中添加GroupID列?

时间:2015-03-05 22:06:21

标签: tsql

我试图动态创建GroupID列。以下是我需要的样子。如何动态添加基于ParentJob的GroupID?

ParentJob   ParentPart  ParentDescription    ParentCompleteDate      GroupID
00000111    360120   4/1 Gal-Egg Food Color     2002-01-13             1 
00000111    360120   4/1 Gal-Egg Food Color     2002-01-13             1
00000111    360120   4/1 Gal-Egg Food Color     2002-01-13             1
00000111    360120   4/1 Gal-Egg Food Color     2002-01-13             1
00000155    360120   4/1 Gal-Egg Food Color     2002-01-11             2
00000155    360120   4/1 Gal-Egg Food Color     2002-01-11             2
00000155    360120   4/1 Gal-Egg Food Color     2002-01-11             2
00000155    360120   4/1 Gal-Egg Food Color     2002-01-11             2
00000155    360120   4/1 Gal-Egg Food Color     2002-01-11             2
00000415    360120   4/1 Gal-Egg Food Color     2002-01-17             3
00000415    360120   4/1 Gal-Egg Food Color     2002-01-17             3
00000415    360120   4/1 Gal-Egg Food Color     2002-01-17             3
00000415    360120   4/1 Gal-Egg Food Color     2002-01-17             3

1 个答案:

答案 0 :(得分:1)

select ..., dense_rank() over (order by ParentJob) as GroupId
from ....