根据说明字段获取日期值

时间:2019-08-28 16:32:51

标签: sql sql-server

我有一个名为actlog的表。我有每个特定案例的活动信息。 现在,我需要获取案件从一个团队转移到另一个团队的日期。

下面是示例。 当案件从1级转移到2级时,我需要获取日期。 即,2018年2月11日

Case    Team    Date    Agent   Summary
123 Level 2     2/13/2018   Ravi    Working on the case
123 Level 2     2/12/2018   Ravi    Working on the case
123 Level 2     2/11/2018   Ravi    Transferred to L2 : Agent Ravi
123 Level 1 2/10/2018   Ram Working on the case
123 Level 1 2/10/2018   Ram Working on the case
123 Level 1 2/10/2018   Ram Working on the case
123 Level 1 2/10/2018   Ram Working on the case

1 个答案:

答案 0 :(得分:2)

使用lag()

select t.*
from (select t.*, lag(team) over (partition by case order by date) as prev_team
      from t
     ) t
where prev_team <> team;

我希望根据实际数据。您也可以尝试依靠summary并使用like

select t.*
from t
where summary like 'Transferred to%';