我想创建一个计算列,以显示按[案例ID],[阶段]和[操作]分组的时间操作结束。阶段的顺序不是必须按字母顺序排列的,可以重复。在[舞台]' C'之后说,我们可以有另一个[舞台]' c'将来
谢谢,
答案 0 :(得分:1)
感谢您更新的测试数据。在询问时,数据类型非常很重要。此外,测试数据应尽可能接近实际数据,否则解决方案通常无法扩展。例如,在测试数据中,值只是时间。按时排序不考虑当天,因此它们都被平等对待。由于这些值实际上是DateTime,我已将其添加到测试数据中。这些表达式将为您提供问题中确定的预期结果。
Rank([Time_Action_Begin],"asc",[Case ID]) as [Rank]
Min([Time_Action_Begin]) OVER (Intersect([Case ID],Next([Rank])))
<强>结果
+---------+-------+----------+------------------------+------------------------+------+
| Case ID | Stage | Action | Time_Action_Begin | Time_Action_End | Rank |
+---------+-------+----------+------------------------+------------------------+------+
| 1 | A | approve | 01/01/2016 11:30:00 PM | 01/02/2016 12:30:00 AM | 1 |
| 1 | A | approve | 01/01/2016 11:30:00 PM | 01/02/2016 12:30:00 AM | 1 |
| 1 | B | approve | 01/02/2016 12:30:00 AM | 01/02/2016 1:30:00 AM | 3 |
| 1 | B | approve | 01/02/2016 12:30:00 AM | 01/02/2016 1:30:00 AM | 3 |
| 1 | C | approve | 01/02/2016 1:30:00 AM | 01/02/2016 2:30:00 AM | 5 |
| 1 | C | approve | 01/02/2016 1:30:00 AM | 01/02/2016 2:30:00 AM | 5 |
| 1 | D | approve | 01/02/2016 2:30:00 AM | 01/02/2016 3:30:00 AM | 7 |
| 1 | D | approve | 01/02/2016 2:30:00 AM | 01/02/2016 3:30:00 AM | 7 |
| 1 | E | approve | 01/02/2016 3:30:00 AM | 01/02/2016 4:30:00 AM | 9 |
| 1 | E | approve | 01/02/2016 3:30:00 AM | 01/02/2016 4:30:00 AM | 9 |
| 1 | F | complete | 01/02/2016 4:30:00 AM | 01/02/2016 5:30:00 AM | 11 |
| 1 | F | complete | 01/02/2016 4:30:00 AM | 01/02/2016 5:30:00 AM | 11 |
| 1 | C | approve | 01/02/2016 5:30:00 AM | | 13 |
| 1 | C | approve | 01/02/2016 5:30:00 AM | | 13 |
| 2 | A | approve | 01/01/2016 10:30:00 PM | 01/02/2016 12:30:00 AM | 1 |
| 2 | A | approve | 01/01/2016 10:30:00 PM | 01/02/2016 12:30:00 AM | 1 |
| 2 | B | approve | 01/02/2016 12:30:00 AM | 01/02/2016 2:30:00 AM | 3 |
| 2 | B | approve | 01/02/2016 12:30:00 AM | 01/02/2016 2:30:00 AM | 3 |
| 2 | C | approve | 01/02/2016 2:30:00 AM | 01/02/2016 3:30:00 AM | 5 |
| 2 | C | approve | 01/02/2016 2:30:00 AM | 01/02/2016 3:30:00 AM | 5 |
| 2 | D | approve | 01/02/2016 3:30:00 AM | 01/02/2016 4:30:00 AM | 7 |
| 2 | D | approve | 01/02/2016 3:30:00 AM | 01/02/2016 4:30:00 AM | 7 |
| 2 | E | approve | 01/02/2016 4:30:00 AM | 01/02/2016 5:30:00 AM | 9 |
| 2 | E | approve | 01/02/2016 4:30:00 AM | 01/02/2016 5:30:00 AM | 9 |
| 2 | F | complete | 01/02/2016 5:30:00 AM | 01/02/2016 6:30:00 AM | 11 |
| 2 | F | complete | 01/02/2016 5:30:00 AM | 01/02/2016 6:30:00 AM | 11 |
| 2 | C | approve | 01/02/2016 6:30:00 AM | | 13 |
| 2 | C | approve | 01/02/2016 6:30:00 AM | | 13 |
+---------+-------+----------+------------------------+------------------------+------+