well,im sort of new to mysql im stuck with the following scenario:
SELECT
h.machine_id,
h.pin_no,
h.created_at,
(SELECT
created_at
FROM
history AS h1
WHERE
h1.created_at > h.created_at
AND h1.machine_id = h.machine_id
AND h1.pin_no = h.pin_no
AND h1.state = 1
LIMIT 1) AS ended_at,
TIMEDIFF(ended_at,created_at) as elapsed
FROM
history AS h
WHERE
h.state = 0
i would like to use the value from subquery in a function,such as datediff, how can i achieve that? i would use cte if it was mssql :)