Re: Aggregate functions on groups

2019-08-31 Thread Rich Shepard
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

Re: Aggregate functions on groups

2019-08-30 Thread Morris de Oryx
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: select tributary, common_name, scientific_name, sum(count_value) as fish_seen, count(cou

Re: Aggregate functions on groups [RESOLVED]

2019-08-30 Thread Rich Shepard
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

Aggregate functions on groups

2019-08-30 Thread Rich Shepard
Tables hold data on fish counts by stream name, species, and (unreported) collection dates. I'm trying to write a query that returns the total number of each species in each stream. The latest attempt is (lines wrapped by alpine; submitted as one line): \copy (select f.stream_tribs, f.count_valu