I looked through a lot of questions on this site, but could not find a solution. I have a table:
Date GroupID CHANNEL
02/24/2015 1 A
02/26/2015 1 B
02/27/2015 1 C
03/21/2015 2 D
02/20/2015 3 E
02/25/2015 3 D
02/28/2015 4 C
03/03/2015 5 B
03/05/2015 5 E
03/10/2015 5 D
03/11/2015 5 A
03/14/2015 5 C
03/23/2015 5 F
03/28/2015 6 E
Channels are limited to 'A, B, C, D, E, F. It has quite a few lines with different GROUPIDs.
I need to get this table:
Date GroupID Channel isFirst isLast Channelsingroup Daysbeforelast
02/24/2015 1 TRUE FALSE 3 3
02/26/2015 1 B FALSE FALSE 3 1
02/27/2015 1 C FALSE TRUE 3 0
03/21/2015 2 D TRUE TRUE 1 0
02/20/2015 3 E TRUE FALSE 2 5
02/25/2015 3 D FALSE FALSE 2 0
02/28/2015 4 C TRUE TRUE 1 0
03/04/2015 5 B TRUE FALSE 6 19
03/05/2015 5 E FALSE FALSE 6 18
03/10/2015 5 D FALSE FALSE 6 13
03/11/2015 5 FALSE FALSE 6 12
03/14/2015 5 C FALSE FALSE 6 9
03/23/2015 5 F FALSE FALSE 6 0
03/28/2015 6 E TRUE TRUE 1 0
IsFirst = TRUE when the channel is the first in a row group with the same identifier, sorted by time; otherwise FALSE.
IsLast = TRUE when the Channel is the last in a group of rows with the same GroupID, sorted by time; otherwise FALSE.
Channelsingroup - the number of lines in one group (with the same group identifier)
Daysbeforelast - dated in days between the last line in the group and the current.
I do not have access to create or update the table, just for selection.
I hope this data makes sense; any questions, please let me know.
source share