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 B0E3A9DCA15 for ; Sat, 18 Feb 2006 03:58:07 -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 90014-03 for ; Sat, 18 Feb 2006 03:58:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id B867E9DCA03 for ; Sat, 18 Feb 2006 03:58:05 -0400 (AST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1FAMyh-0006hH-00; Sat, 18 Feb 2006 02:58:03 -0500 To: "Alfred" <99m@myway.com> Cc: pgsql-sql@postgresql.org Subject: Re: Tough Problem -- Record Checkouts References: <1139851981.176833.302970@g43g2000cwa.googlegroups.com> In-Reply-To: <1139851981.176833.302970@g43g2000cwa.googlegroups.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 18 Feb 2006 02:58:03 -0500 Message-ID: <87bqx514l0.fsf@stark.xeocode.com> Lines: 30 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.13 required=5 tests=[AWL=0.130] X-Spam-Score: 0.13 X-Spam-Level: X-Archive-Number: 200602/233 X-Sequence-Number: 24243 "Alfred" <99m@myway.com> writes: > CO | N > ------+----------------------- > 0 | 15-59 > 1 | 0, 16-59 > 2 | 0-1, 17-59 > 15 | 0-14, 30-59 > 16 | 0-15, 31-59 > 30 | 0-29, 45-59 > 31 | 0-30, 46-59 > 45 | 0-44 > 46 | 1-45 > 59 | 14-58 > > This becomes some kind of UPDATE statement with a complex WHERE clause. That's usually a sign you're storing the data in the wrong form. Why are you storing just the minutes and not the absolute timestamp of the checkout? In any case the where clause isn't all that complex. I think you've confused yourself by drawing the inverse table of what you need. You need the range of CO to expire for a given N, not the range of N in which you should expire a given CO. WHERE co BETWEEN 0 AND n-15 OR co BETWEEN n+1 AND n+45 -- greg