From: | Malcolm Hutty <msah-postgresql(at)hutty(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | "next" |
Date: | 2002-12-02 16:54:43 |
Message-ID: | 3DEB9053.2020203@hutty.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Suppose I've got a table containing train departure and arrival times,
like so:
SELECT id,departure,arrival,arrival-departure AS duration FROM timetable;
id | departure | arrival | duration
----+------------------------+------------------------+----------
1 | 2002-12-02 14:00:00+00 | 2002-12-02 15:00:00+00 | 01:00
7 | 2002-12-02 17:00:00+00 | 2002-12-03 14:00:00+00 | 21:00
2 | 2002-12-03 17:00:00+00 | 2002-12-03 18:00:00+00 | 01:00
6 | 2002-12-03 21:00:00+00 | 2002-12-04 04:00:00+00 | 07:00
4 | 2002-12-04 10:00:00+00 | 2002-12-04 18:00:00+00 | 08:00
5 | 2002-12-05 08:00:00+00 | 2002-12-05 10:00:00+00 | 02:00
Can anyone advise as to the best way to express the following question
in SQL: "What's the earliest arrival time where there isn't a
subsequent departure time within (e.g.) 7 hours?". The table will
contain many rows.
I feel foolish - it _looks_ simple - but I've been banging my head
against the wall trying to implement this as either a JOIN or a
subselect, and it's starting to hurt.
Malcolm.
From | Date | Subject | |
---|---|---|---|
Next Message | David C.Oshel | 2002-12-02 17:02:10 | Installing readline, compiling 7.3 on Mac OS X 10.2.2 |
Previous Message | Patrick | 2002-12-02 16:53:39 | Re: how to recover superuser password ? |