From: | Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il> |
---|---|
To: | kcolagio(at)wc(dot)eso(dot)mc(dot)xerox(dot)com (Kevin Colagio), pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] Time related question... |
Date: | 1998-06-17 13:02:15 |
Message-ID: | l03110705b1ad6d60a3ab@[147.233.159.109] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
At 15:33 +0300 on 17/6/98, Kevin Colagio wrote:
>
> My question is: what is the SQL statement that will allow me to find:
> 1) a list of the calls where the difference between the dateentered and
> dateclosed is less than (say) 3 days.
Here is an example:
testing=> \d example4
Table = example4
+--------------------------+------------------------------+-------+
| Field | Type | Length|
+--------------------------+------------------------------+-------+
| entered | datetime | 8 |
| closed | datetime | 8 |
+--------------------------+------------------------------+-------+
testing=> SELECT * FROM example4;
entered |closed
----------------------------+----------------------------
Wed Jan 14 00:00:00 1998 IST|Thu Jan 15 00:00:00 1998 IST
Wed Jan 14 00:00:00 1998 IST|Sun Jan 18 00:00:00 1998 IST
Thu Mar 19 23:00:00 1998 IST|Tue Feb 17 00:00:00 1998 IST
Wed Apr 01 00:00:00 1998 IDT|Thu Apr 01 00:00:00 1999 IST
Mon Jun 01 00:00:00 1998 IDT|Wed Jun 03 00:00:00 1998 IDT
(5 rows)
testing=> SELECT *
testing-> FROM example4
testing-> WHERE (closed - entered) < '3 days';
entered |closed
----------------------------+----------------------------
Wed Jan 14 00:00:00 1998 IST|Thu Jan 15 00:00:00 1998 IST
Thu Mar 19 23:00:00 1998 IST|Tue Feb 17 00:00:00 1998 IST
Mon Jun 01 00:00:00 1998 IDT|Wed Jun 03 00:00:00 1998 IDT
(3 rows)
If you're wondering why you got the second row, it's because it has an
entered date which is greater than the closed date. A negative difference
is less than 3 days... So you should actually make sure this doesn't
happen, like this:
testing=> SELECT *
testing-> FROM example4
testing-> WHERE closed > entered
testing-> AND (closed - entered) < '3 days';
entered |closed
----------------------------+----------------------------
Wed Jan 14 00:00:00 1998 IST|Thu Jan 15 00:00:00 1998 IST
Mon Jun 01 00:00:00 1998 IDT|Wed Jun 03 00:00:00 1998 IDT
(2 rows)
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
From | Date | Subject | |
---|---|---|---|
Next Message | Herouth Maoz | 1998-06-17 13:17:15 | Re: [SQL] Time related question... |
Previous Message | Patrice Hédé | 1998-06-17 12:45:15 | Re: [SQL] Time related question... |