I have a field in my Oracle SQL table:
LOGIN_TIME – this is a result after calculating the ENDTIME minus STARTTIME fields
I am trying to achieve:
- if the STATUS field = AWAY then the LOGIN_TIME should = 0
- otherwise keep the calculation ENDTIME minus STARTTIME
- I would also like to show the LOGIN_TIME field as HH:MM:SS if possible
Please can you advise? This is my code so far:
SELECT DISTINCT a.SESSIONID,
d.USERNAME,
d.FNAME|| ' '||d.LNAME AS FULLNAME,
d.HOMEWKGRPID_NAME,
a.STARTTIME,
a.ENDTIME,
a.STATUS,
a.ENDTIME-A.STARTTIME AS LOGIN_TIME
from USERACCESSLOGSTATUS a INNER JOIN USERTABLE d ON a.USERID=d.ID
WHERE a.RDB_INSERT_DATE >= to_timestamp('2024-09-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
AND d.HOMEWKGRPID_NAME LIKE ('REGION_%')
A previous comment advised to use a CASE statement to try and achieve this but I was unable to get this to work.
Example of current output