I have a query that I have simplified and written below.
How do I display the time difference of 2 fields that were calculated as 2 separate inline select statements?
SELECT x.name ,
( SELECT data.ts
FROM data
WHERE prim_key = x.prim_key and roll_no ='1'
) **starttime** ,
( SELECT data.ts
FROM woman_data
WHERE prim_key = x.prim_key and roll_no ='10'
) **endtime**
, **TIME_TO_SEC( TIMEDIFF( endtime , starttime)** as timediff // This line does not work.It cannot recognize endtime ans starttime
FROM data x
INNER JOIN y
ON x.prim_key = y.prim_key
ORDER BY x.prim_key
try this:
starttime and endtime are derived columns, you cannot use it in the same select statement..
You have to create a derived table then use these columns the a query outside