Sample Header Ad - 728x90

PostgreSQL Query - how to subtract timestamps and format durations (with builitin functions or otherweise)

-1 votes
1 answer
1866 views
I am looking for a solution to a problem with a select statement where I am trying to display the sleep duration. ### Sleep Table here is my columns from sleep TABLE Here is the select statement I have so far:
select wakeuptime,hour from
		(
			select patientid, 
                   sum(s.duration) as hour, 
                   Date(s.wake_up_time) as wakeuptime 
            from sleep s
			where patientid = pid::varchar
			group by patientid, Date(s.wake_up_time) 
			order by Date(s.wake_up_time) desc
		) s
		order by s.wakeuptime asc;
I need to calculate Sum (wake_up_time - time_to_bed) where it should convert minutes into hours for example 55mins + 15mins should return 1hr 10mins.
Asked by Badrinarayanan (1 rep)
Aug 19, 2021, 05:26 AM
Last activity: Aug 26, 2021, 07:13 AM