Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nABNq-0007WF-CE for pgsql-sql@arkaria.postgresql.org; Wed, 19 Jan 2022 13:52:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nABNp-0006xR-7g for pgsql-sql@arkaria.postgresql.org; Wed, 19 Jan 2022 13:52:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nABNo-0006vu-PM for pgsql-sql@lists.postgresql.org; Wed, 19 Jan 2022 13:52:16 +0000 Received: from mailtransmit04.runbox.com ([2a0c:5a00:149::25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nABNm-0001PI-Ox for pgsql-sql@lists.postgresql.org; Wed, 19 Jan 2022 13:52:16 +0000 Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1nABNk-00BR5r-J6; Wed, 19 Jan 2022 14:52:12 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Transfer-Encoding:Content-Type:MIME-Version: Message-ID:Date:Subject:In-Reply-To:References:To:From; bh=DKylYiNotqB2uYY5uOngk3KePlA6h5Pw+Yyg/m+lgxw=; b=Xi/k0z55rXXV1hQxwA330kzByz WEN58Fr7YUErfqqIdTAiEnzIxanPwC2j06bY19hXMerRVWt0Q0rJRIhLQDvcHHxJRnHuM0Or7UNbX I5oidawp3ojaf4uUyQ9IdO7tCryr9FdXZyqejM/zprK/fnullIZkI6qZ9JGFJEUfhWIMKE0kYKNQY nNcWIVBHg8TVyy8eCJm6t8pRwhy8NXSB+Woa6UFNvhYZPIJL+MretGrPQkCtyeHXmMZejTz61KZbQ rcALHv8IoqOfbkBAmYgT/QPhzJAn3FSpWnLaCoCYUguBPUkWHljVBcpU6Lt3FIWqmP4lxvW6G52w1 ADyhsWJg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1nABNj-0002CV-IH; Wed, 19 Jan 2022 14:52:11 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (300526)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1nABNX-0006bm-Vw; Wed, 19 Jan 2022 14:52:00 +0100 From: "Mike Sofen" To: "'Richard Klingler'" , References: <20220119141711201637.c796844d@klingler.net> <20220119143718285650.48772b27@klingler.net> In-Reply-To: <20220119143718285650.48772b27@klingler.net> Subject: RE: Clean up shop database Date: Wed, 19 Jan 2022 05:51:56 -0800 Message-ID: <122401d80d3b$ba859da0$2f90d8e0$@runbox.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQIvFn+ZjdYmuF98WdVk9MBbAQWq6wFyBTR9AfDeYDOroTD3cA== Content-Language: en-us List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > From: Richard Klingler Sent: Wednesday, January 19, 2022 5:37 AM > On Wed, 19 Jan 2022 06:32:19 -0700, Rob Sargent wrote: > > > >> No it does not...but I assume it lists products that where at least > >> ordered before January 1st 2021 as it contains lower product IDs. > >> > >> Hmm..gives me: > >> > >>> ERROR: function max(boolean) does not exist > >> LINE 5: having max(o.orderdate < '2021-01-01') > >> > >> > > Sorry > >> > >> max(o.orderdate )< '2021-01-01' > > > >> > You're a genius :-) > Looks perfect... There is one caveat here: unless you are 100% certain that the product.pieces count is 100% accurate, you should sum the orderitems.productid. It is pretty common for the indirect counts (like product.pieces) to get out of sync with the "normal" source of truth (line items). This does depend on design of your system, of course. Mike