X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BAA8F9DC801 for ; Thu, 26 Jan 2006 07:58:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76832-01 for ; Thu, 26 Jan 2006 07:58:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.187]) by postgresql.org (Postfix) with ESMTP id E114C9DC815 for ; Thu, 26 Jan 2006 07:58:17 -0400 (AST) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu9) with ESMTP (Nemesis), id 0ML2xA-1F25lZ3oR7-000490; Thu, 26 Jan 2006 12:58:18 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1F25lY-0002fC-00 for pgsql-sql@postgresql.org; Thu, 26 Jan 2006 12:58:16 +0100 Date: Thu, 26 Jan 2006 12:58:16 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: question with times and intervals Message-ID: <20060126115816.GA9924@webserv.wug-glas.de> Mail-Followup-To: "A. Kretschmer" , pgsql-sql@postgresql.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-DEST: 208 X-MSMail-Priority: High X-Message-Flag: Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) X-OS: Linux - weil ich es mir Wert bin! X-Info: registrierter Linux-User 97922 http://counter.li.org User-Agent: mutt-ng 1.5.9i (Linux) X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.225 required=5 tests=[AWL=-0.169, MISSING_MIMEOLE=1.394] X-Spam-Score: 1.225 X-Spam-Level: * X-Archive-Number: 200601/180 X-Sequence-Number: 23969 Hi, I have a table like this: test=# select * from status_log ; id | status | t_start | t_end ----+--------+------------------------+------------------------ 1 | 1 | 2006-01-20 23:00:00+01 | 2006-01-21 06:00:00+01 1 | 1 | 2006-01-21 06:00:00+01 | 2006-01-21 22:00:00+01 1 | 2 | 2006-01-21 22:00:00+01 | 2006-01-22 05:00:00+01 1 | 1 | 2006-01-22 05:00:00+01 | 2006-01-22 15:00:00+01 1 | 2 | 2006-01-22 15:00:00+01 | 2006-01-23 02:00:00+01 (5 rows) Now i need for a particular intervall (one day or two days, entires days) the accumulated time for id=X and status=Y. Exampel: id=1, status=1, date=2006-01-21: from 00:00:00 - 06:00:00 and 06:00:00 - 22:00:00 ===> 6 hours + 16 hours = 22 hours id=1, status=2, date=2006-01-21: from 22:00:00 - 23:59:59 ===> 2 hours I need also this for a week or month. How can i calculate this? Thanks very much for help. -- Andreas Kretschmer (Kontakt: siehe Header) Heynitz: 035242/47215, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net === Schollglas Unternehmensgruppe ===