select day_of_week, avg(booking_time)
from(SELECT check_in_date - booked_at as booking_time, EXTRACT (dow FROM
check_in_date)day_of_week
FROM bookings
) as table1
where EXTRACT(epoch FROM booking_time)/3600 > 0
group by day_of_week
order by avg(booking_time) desc;
here's the output table:
day_of_week | avg |
---|---|
4.0 | 72 days 32:01:52.694268 |
5.0 | 57 days 34:00:09.228322 |
3.0 | 50 days 26:30:19.840091 |
6.0 | 41 days 33:12:01.010234 |
0.0 | 36 days 14:35:36.59173 |
2.0 | 34 days 28:15:35.384787 |
1.0 | 31 days 10:52:57.718717 |
The quick answer:
select extract(days from justify_hours('72 days 32:01:52.694268'::interval));
73
Further explanation. Use justify_hours
fromDateTime functions to convert the hours portion of the interval to a day if appropriate.
select justify_hours('72 days 32:01:52.694268'::interval);
justify_hours
-------------------------
73 days 08:01:52.694268
Then use extract
from the same link above to pull the days portion of the interval out:
select extract(days from justify_hours('72 days 32:01:52.694268'::interval));
extract
---------
73
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.