php - Postgresql usage of aggregates and non-aggregate columns, grouping by -


some things in lecture , in lab assignment not explained well. having trouble displaying correct information. here database info, reference me. the database tables info query trying execute the postgresql php select statement

this results in sql error being throwned

connected database! query failed: error: column "city.name" must appear in group clause or used in aggregate function line 3: city.name ^

now if add city.name group clause, returns 4096 rows! dont want happen, results have group country name 232 rows. want display country name, city name, , city highest population in country. city name throwing me off, im guessing there more complicated more syntax heavy solution. can provide. -tom reese

you need this:

select         country.name,         city.name,         mp.maxpop         lab6.country,         lab6.city,         (select                 country_code,                 max(population) maxpop                         lab6.city         group                 country_code         ) mp         country.country_code=mp.country_code ,         country.country_code=city.county_code ,          mp.maxpop=city.population 

notes:

  • this can give more result/county.
  • your original query doesn't work because in ansi sql can't return aggregated or group expressions "group by" query. (as error mentions)

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -