I'm trying to look for the day interval between customer latest booking and oldest booking.
I used max(booking_date)
to identify a customer's latest booking date, and min(booking_date)
as the oldest booking date. Both are in datetime format.
I tried using datediff('day', max(booking_date), min(booking_date))
to find the day interval between the bookings, but it didn't work.
My query:
select
u.id,
datediff(day, max(b.date), min(b.date))
from bookings b
left join users u on b.user_id = u.id
Error message:
Error running query: function datediff(timestamp with time zone, timestamp with time zone) does not exist
Anyone please assist. Thanks a bunch!