I have a table records of store id, processing batch id and start time as follows:
|store_id | batch_id | process_start_time | | A | 1 | 10 | | B | 1 | 40 | | C | 1 | 30 | | A | 2 | 400 | | B | 2 | 800 | | C | 2 | 600 | | A | 3 | 10 | | B | 3 | 80 | | C | 3 | 90 | Here, rows needed to be grouped by batch_id and time_taken is difference of process_start_time of store A and store C.
So, the expected result would be:
batch_id | time_taken 1 | 20 2 | 200 3 | 80 I tried to do something like:
select batch_id, ((select process_start_time from records where store_id = 'C') - (select process_start_time from records where store_id = 'A')) as time_taken from records group by batch_id; But couldn't figure out to select specific rows in that particular group.
Thank you for looking into!
Update: the process_start_time column not necessarily max for store C