The first column (CALL_START) is time on which somebody of some particular ID (CALLER_ID) made a call. see snippet of data here.
Now I want to pick out the next call of the same ID and store it in a new column named as 'Next_call' and if there is no next call it stores NULL.
So this is the result that I want below.
CALL_START NEXT_CALL CALLER_ID
2017-01-14 10:50:38 NULL 2837061
2017-01-14 10:21:03 2017-01-14 10:50:38 2837061
The CALLER_ID should be same to find the next call, so I have to find a next call according to each ID.
I have tried this so far.
select CALL_START, CALLER_ID
from call_data.records
where CALL_START > (select CALL_START from call_data.records group by CALLER_ID)
;
This query does not work for me and I am not sure how to do it exactly as I am learning sql records is a temp table which I joined using different table's data.
I am new to learning SQL, so any help would be greatly appreciated.