Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i44Nx-0003oN-96 for pgsql-general@arkaria.postgresql.org; Sat, 31 Aug 2019 14:29:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i44Nw-0001VY-2p for pgsql-general@arkaria.postgresql.org; Sat, 31 Aug 2019 14:29:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i44Nv-0001T5-ML for pgsql-general@lists.postgresql.org; Sat, 31 Aug 2019 14:29:47 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i44Np-0003bL-5z for pgsql-general@postgresql.org; Sat, 31 Aug 2019 14:29:46 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id E9C859939A for ; Sat, 31 Aug 2019 07:29:39 -0700 (PDT) Date: Sat, 31 Aug 2019 07:29:39 -0700 (PDT) From: Rich Shepard To: pgsql-general Subject: Re: Aggregate functions on groups In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, 31 Aug 2019, Morris de Oryx wrote: > Your tributaries and fish master tables make sense. If I read your code > right, you're grouping by too many columns. I flattened the data into a > survey table for this simple example: Morris, I'm still learning about postgres groups. My approach is to group on the column of interest, then add more when psql tells me to do so. > select tributary, > common_name, > scientific_name, > sum(count_value) as fish_seen, > count(count_value) as observations_made > > from survey > > group by 1,2,3 -- The GROUP BY clause can use positions on the select > list, if you feel like typing less. I will look more at this approach; at first glance it appears to address one query but not all those needed. > But this is not why I'm answering. I'm responding as I wanted to make sure > that you're aware of the pg-similarity extension: > https://salsa.debian.org/postgresql/pg-similarity Thanks for the URL. I'll definintely read about similarity. Regards, Rich