I have query like this
SELECT user_ID, tanggal, kode_layanan, nomor_antrian, aksi_ID,jam
FROM `transaksi`
WHERE tanggal = '2018-10-11'
AND kode_layanan = 'A'
AND aksi_ID BETWEEN 4 AND 9
and the result is like the picture below
what I want to do is do calculation time difference "jam". I know there are similar question, but i think its difference condition. so how to solve query ? thanks
Best Answer
I think your column definition will be as shown in this query:
The logic is: "if the current row has an
aski_ID
value of '4' then find the time difference between the current row'sjam
value, and thejam
value of the row having anaski_ID
value of 9 and anomor_antrian
value that is the maximumnomor_antrian
value less than the current row'snomor_antrian
value".You can see this result working on db-fiddle.