From: Rich Shepard <rshepard@appl-ecosys.com>
To: pgsql-general@postgresql.org
Subject: Re: Aggregate functions on groups [RESOLVED]
Date: Fri, 30 Aug 2019 10:41:26 -0700 (PDT)
Message-ID: <alpine.LNX.2.20.1908301038010.22705@salmo.appl-ecosys.com> (raw)
In-Reply-To: <CAPhAwGwvHycfGVQ9rnyJ4nh2EzKyFWbQ9daki7zsjpjXePWX1Q@mail.gmail.com>
References: <alpine.LNX.2.20.1908301003500.22705@salmo.appl-ecosys.com>
<CAPhAwGwvHycfGVQ9rnyJ4nh2EzKyFWbQ9daki7zsjpjXePWX1Q@mail.gmail.com>
On Fri, 30 Aug 2019, John W Higgins wrote:
> You are grouping by count_value which means that you are asking the system
> to return a row for each different count_value.
John,
I didn't realize this.
> So if you remove the f.count_value from the select statement (not the
> sum(f.count_value)) - and you remove f.count_value from the group_by and
> order_by statements - you should get what you want
Aha. I thought I had to select f.count_value in order to obtain
sum(f.count_value); it's been a long time since I needed to do something
like this.
> Something like
>
> \copy (select f.stream_tribs, sum(f.count_value),
> i.common_name, i.sci_name from fish_counts as f, itis as i where
> f.stream_tribs like '%Nehalem River%' group by f.stream_tribs,
> i.common_name, i.sci_name order by f.stream_tribs,
> i.common_name, i.sci_name) to
> '/home/rshepard/projects/oregon/mohler_sand/data/fish/fishes.dat';
Thanks very much!
Rich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: rshepard@appl-ecosys.com
Subject: Re: Aggregate functions on groups [RESOLVED]
In-Reply-To: <alpine.LNX.2.20.1908301038010.22705@salmo.appl-ecosys.com>
References: <alpine.LNX.2.20.1908301003500.22705@salmo.appl-ecosys.com> <CAPhAwGwvHycfGVQ9rnyJ4nh2EzKyFWbQ9daki7zsjpjXePWX1Q@mail.gmail.com> <alpine.LNX.2.20.1908301038010.22705@salmo.appl-ecosys.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox