Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id C1AD92E017C for ; Sat, 15 Mar 2008 13:05:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 19234-04 for ; Sat, 15 Mar 2008 13:05:19 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from tomts13-srv.bellnexxia.net (tomts13-srv.bellnexxia.net [209.226.175.34]) by postgresql.org (Postfix) with ESMTP id EFF1D2E0179 for ; Sat, 15 Mar 2008 13:05:18 -0300 (ADT) Received: from toip7.srvr.bell.ca ([209.226.175.124]) by tomts13-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20080315160517.OZZU29750.tomts13-srv.bellnexxia.net@toip7.srvr.bell.ca> for ; Sat, 15 Mar 2008 12:05:17 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtAEAFCQ20dBX4fQ/2dsb2JhbACBWqZS Received: from bas3-london14-1096779728.dsl.bell.ca (HELO t60p.bax.ca) ([65.95.135.208]) by toip7.srvr.bell.ca with ESMTP; 15 Mar 2008 12:07:27 -0400 Message-ID: <47DBF3BD.9080306@sympatico.ca> Date: Sat, 15 Mar 2008 12:05:17 -0400 From: Frank Bax User-Agent: Thunderbird 2.0.0.6 (X11/20070818) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Counting days ... References: <200803132025.27821.aarni@kymi.com> <200803141713.40589.aarni@kymi.com> <47DAA330.8070409@sympatico.ca> <200803141925.26039.aarni@kymi.com> In-Reply-To: <200803141925.26039.aarni@kymi.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/88 X-Sequence-Number: 30416 Aarni Ruuhimäki wrote: > So the WHERE clause would go like: > > group_id = 1 AND res_start_day < '$date1' AND res_end_day >= '$date1' [AND > region_id = $region_id] [AND company_id = $company_id] [AND product_id = > $product_id] > OR > group_id = 1 AND res_start_day = '$date1' AND res_end_day >= '$date1' [AND > region_id = $region_id] [AND company_id = $company_id] [AND product_id = > $product_id] > OR > group_id = 1 AND res_start_day >= '$date1' AND res_start_day < '$date2' AND > res_end_day >= '$date1' [AND region_id = $region_id] [AND company_id = > $company_id] [AND product_id = $product_id] This is smaller; and should be equivalent: group_id = 1 AND ( res_start_day <= '$date1' AND res_end_day >= '$date1' OR res_start_day >= '$date1' AND res_start_day < '$date2' ) [AND region_id = $region_id] [AND company_id = $company_id] [AND product_id = $product_id]