今天是个好日子。我一直无法提出解决方案,正在寻求任何帮助。我有一个表,我想为其添加一列:
ID Time_Stamp Activity_Log
1254 6/1/2013 8:00:00AM 'Ticket was opened by user A'
1254 6/2/2013 8:20:00AM 'Comment was logged by user B'
1254 6/4/2013 8:25:00AM '**Ticket was transferred to Group 1**'
1254 6/7/2013 8:50:00AM 'Comment was logged by user B'
1254 6/11/2013 10:00:00AM 'Comment was logged by user C'
1254 6/12/2013 12:00:00PM '**Ticket was transferred to Group 2**'
7589 6/3/2013 11:00:00PM 'Ticket was opened by user A'
7589 6/5/2013 1:00:00PM 'Comment was logged by user C'
7589 6/7/2013 2:00:00PM 'Resolution provided by user C'
7589 6/11/2013 5:00:00PM 'Ticket resolved by user C'
8526 6/3/2013 7:00:00PM 'Ticket opened by user D'
8526 6/4/2013 2:00:00PM '**Ticket was transferred to Group 2**'
8526 6/5/2013 1:00:00PM 'Comment was logged by user G'
8526 6/8/2013 5:00:00PM '**Ticket was resolved by user C**'
这是我希望新列 Group 的样子:
ID Time_Stamp Activity_Log Group
1254 6/1/2013 8:00:00AM 'Ticket was opened by user A' NULL
1254 6/2/2013 8:20:00AM 'Comment was logged by user B' NULL
1254 6/4/2013 8:25:00AM '**Ticket was transferred to Group 1**' Group 1
1254 6/7/2013 8:50:00AM 'Comment was logged by user B' Group 1
1254 6/11/2013 10:00:00AM 'Comment was logged by user C' Group 1
1254 6/12/2013 12:00:00PM '**Ticket was transferred to Group 2**' Group 2
7589 6/3/2013 11:00:00PM 'Ticket was opened by user A' NULL
7589 6/5/2013 1:00:00PM 'Comment was logged by user C' NULL
7589 6/7/2013 2:00:00PM 'Resolution provided by user C' NULL
7589 6/11/2013 5:00:00PM 'Ticket resolved by user C' NULL
8526 6/3/2013 7:00:00PM 'Ticket opened by user D' NULL
8526 6/4/2013 2:00:00PM '**Ticket was transferred to Group 2**' Group 2
8526 6/5/2013 1:00:00PM 'Comment was logged by user G' Group 2
8526 6/8/2013 5:00:00PM '**Ticket was resolved by user C**' Group 2
如果 Activity_Log 是 LIKE '%xx%',我想用一个字符串添加这个组列,并且基于 ID 和 Time_Stamp 之后的每一行。一些 ID 在 activity_log 中没有该语言,并且所有行的 Group 列都为 NULL。对于那些这样做的人,我想在 activity_log 为 LIKE '%transfer to Group x%' 时开始,并在 activity_log 为 '%Transfer to Group x%' 或 '%ticket wassolved%' 时结束。我尝试使用 OVER (partition by) 编写查询以按 ID 划分,但没有成功。
谢谢