我正在尝试创建一个列来正确标记Estimator的工作量变化。
我已经能够使用DENSE_RANK()函数使用下面的代码了,但它并不是我想要的。我无法确定要组织的起点和终点。我在下面列出了当前和期望的输出。
当前代码:
SELECT *,
DENSE_RANK() OVER (ORDER BY Estimator, Effort) AS Group
FROM #Estimating_with_Breakpoints
ORDER BY Estimator, Date, DateType
当前输出:
Job Name DateType Date Effort Group
Hidden Lakes Apartments Start 3/8/2017 50 6
Hidden Lakes Apartments Breakpoint 4/13/2017 50 6
Hidden Lakes Apartments Finish 4/13/2017 0 4
Dr. Biggs Joint Institute Breakpoint 5/1/2017 0 4
Dr. Biggs Joint Institute Start 5/1/2017 33 5
Bonita Springs Library Breakpoint 5/22/2017 33 5
North Ft. Myers Library Breakpoint 5/22/2017 83 7
Bonita Springs Library Start 5/22/2017 83 7
North Ft. Myers Library Start 5/22/2017 133 9
Dr. Biggs Joint Institute Breakpoint 6/5/2017 133 9
Dr. Biggs Joint Institute Finish 6/5/2017 100 8
Bonita Springs Library Breakpoint 6/19/2017 100 8
North Ft. Myers Library Breakpoint 6/19/2017 50 6
Bonita Springs Library Finish 6/19/2017 50 6
North Ft. Myers Library Finish 6/19/2017 0 4
期望的输出:
Job Name DateType Date Effort Group
Hidden Lakes Apartments Start 3/8/2017 50 1
Hidden Lakes Apartments Breakpoint 4/13/2017 50 1
Hidden Lakes Apartments Finish 4/13/2017 0 2
Dr. Biggs Joint Institute Breakpoint 5/1/2017 0 2
Dr. Biggs Joint Institute Start 5/1/2017 33 3
Bonita Springs Library Breakpoint 5/22/2017 33 3
North Ft. Myers Library Breakpoint 5/22/2017 83 3
Bonita Springs Library Start 5/22/2017 83 3
North Ft. Myers Library Start 5/22/2017 133 4
Dr. Biggs Joint Institute Breakpoint 6/5/2017 133 4
Dr. Biggs Joint Institute Finish 6/5/2017 100 5
Bonita Springs Library Breakpoint 6/19/2017 100 5
North Ft. Myers Library Breakpoint 6/19/2017 50 5
Bonita Springs Library Finish 6/19/2017 50 5
North Ft. Myers Library Finish 6/19/2017 0 5