pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: kcolagio@wc.eso.mc.xerox.com
To: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Time related question...
Date: Wed, 17 Jun 1998 16:02:15 +0300
Message-ID: <l03110705b1ad6d60a3ab@[147.233.159.109]> (raw)
In-Reply-To: <199806171233.IAA01017@bentley.eso.mc.xerox.com>

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





view thread (4+ messages)  latest in thread

Message-ID: <l03110705b1ad6d60a3ab@[147.233.159.109]>
Permalink:  ../l03110705b1ad6d60a3ab@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03110705b1ad6d60a3ab@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: herouth@oumail.openu.ac.il, kcolagio@wc.eso.mc.xerox.com
  Subject: Re: [SQL] Time related question...
  In-Reply-To: <l03110705b1ad6d60a3ab@[147.233.159.109]>
  References: <199806171233.IAA01017@bentley.eso.mc.xerox.com> <l03110705b1ad6d60a3ab@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox