'teradata gaps between previous date and preceding date by date by employee

I want to get the gap time between records and make that a row.

first record Joe StartDate 5/23/21 8:46 AM EndDate 5/23/21 9 AM,

next record Joe start date 5/23/21 9:23 AM End Date 5/23/21 10:43 AM,

next record Joe start date 5/23/21 8:23 AM End Date 5/23/21 2:01 PM,

next record Joe start date 5/23/21 11:16 AM End Date 5/23/21 2:54 PM,

next record Joe start date 5/23/21 11:26 AM End Date 5/23/21 3:14 PM,

next record Joe start date 5/12/2022 10:17:47 AM End Date 5/12/20224:45:54 PM,

next record Suzy start date 5/2/2022 8:08:26 AM End Date 5/2/2022 2:01:07 PM,

next record Suzy start date 5/1/2022 2:33:09 PM End Date 5/1/2022 2:49:53 PM,

next record Suzy start date 5/1/2022 2:35:02 PM End Date 5/11/2022 3:14:33 PM,

next record Suzy start date 5/12/2022 10:39:23 AM End Date 5/12/2022 4:49:33 PM,

next record JuJu start date 5/2/2022 11:03:14 AM End Date 5/2/2022 1:06:34 PM,

next record JuJu start date 5/2/2022 11:17:26 AM End Date 5/2/2022 1:31:33 PM,

next record JuJu start date 5/2/2022 11:41:12 AM End Date 5/2/2022 1:48:16 PM

I've tried: 'code' Lag(STARTDATE) Over (PARTITION BY ASSIGNEDTO, STARTDATE ORDER BY ASSIGNEDTO,STARTDATE,ENDDATE) AS prev_date, Max(EndDate) Over (PARTITION BY ASSIGNEDTO, EndDate ORDER BY ASSIGNEDTO, EndDate DESC) AS max_start,'code'

Sometimes there's no end date, so that's why I am trying to get the time between the start and end date and the start date previous record and start date of current record, but i also need to see if folks are down and not doing anything? So I have two calculations 1 for HTM = total time from start to End and another that should show time between task or records for that date by employee. 'code' EXAMPLE RECORD: ASSIGNEDTO AUDITDATETIME STARTDATE ENDDATE TASKNAME

Joe 12/10/2021 12:00:00 AM 12/10/2021 4:42:05 PM 12/10/2021 6:10:48 PM Case Review

jUjU 5/17/2022 12:00:00 AM 5/17/2022 10:50:07 AM null Initial Review

jUjU 5/17/2022 12:00:00 AM 5/17/2022 12:03:06 AM null Initial Review

Here I have to calculate between the 5/17 10:50 and 12:03 indicates she completed it in hh.mm BeBe 11/12/2021 12:00:00 AM 11/2/2021 9:23:31 AM 11/2/2021 12:38:25 PM Manual

BeBE 11/2/2021 12:00:00 AM 11/2/2021 4:04:16 PM 11/2/2021 4:15:09 PM Case Review

Here I have to show the gap time between 12:38PM and 4:04 PM



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source