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 1if9F6-00085F-KZ for pgsql-general@arkaria.postgresql.org; Wed, 11 Dec 2019 21:09:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1if9F5-0003Xr-BQ for pgsql-general@arkaria.postgresql.org; Wed, 11 Dec 2019 21:09:55 +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 1if9F4-0003Xk-UA for pgsql-general@lists.postgresql.org; Wed, 11 Dec 2019 21:09:55 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1if9F1-00074C-GM for pgsql-general@lists.postgresql.org; Wed, 11 Dec 2019 21:09:53 +0000 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id D6972262E39 for ; Wed, 11 Dec 2019 13:09:48 -0800 (PST) Date: Wed, 11 Dec 2019 13:09:48 -0800 (PST) From: Rich Shepard To: PostgreSQL General Subject: Re: Counting number of sites with same number of sampling dates In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 11 Dec 2019, Michael Lewis wrote: > Put what you have in a subquery and group/aggregate again. > > select sample_count, count( site_nbr ) FROM ( > select site_nbr, count(distinct sampdate) AS sample_count from wrb_hg_cong > group by site_nbr order by site_nbr > ) sub > group by sample_count; Michael, Well, darn! I totally speced using a subquery. Thank you very much for an important lesson. Best regards, Rich