Sample Header Ad - 728x90

SQL: Need formula to subtract one row from another under the same column

0 votes
1 answer
2184 views
Need assistance with creating a "Datediff"/"CASE" type of formula. I have timestamps in the {incilog} table, in different rows across the same column {incilog.timestamp} that I need to subtract from one another, but only if the {incilog.transtype} equals "TR" from the row that has the {incilog.transtype} equal "FPS". Logic is: If {incilog.transtype} equals "TR" and {incilog.transtype} equals "FPS", then subtract {incilog.timestamp} from {inciog.timestamp} in the corresponding row. Basically, I need to get how many seconds it took from "TR" to "FPS". THANK YOU FOR YOUR TIME AND ASSISTANCE! **EXAMPLE OF DATA** | timestamp | inci_id | transtype | descript | |-----------|---------|-----------|----------| |8/22/2022 12:14:46 AM | 2022264051| TR | Time Received | |8/22/2022 12:17:00 AM | 2022264051| FPS| Fire Pri. Started |
Asked by Drew (3 rep)
Aug 23, 2022, 03:13 PM
Last activity: Aug 23, 2022, 03:54 PM