sql - Raw pg GROUP BY query in rails application -


i have simple sql query trying execute in rails console.

select name, manual_score objectives group manual_score 

but throws error is:

activerecord::statementinvalid: pg::groupingerror: error:  column "objectives.name" must appear in group clause or used in aggregate function 

i have tried prepending table name columns error remains. appericiated. thanks!

the problem listing column not "grouped". should add name group by or remove select.

select name, manual_score objectives group name, manual_score -- or select manual_score objectives group manual_score -- or select count(name), manual_score objectives group manual_score 

why have add column group by or use aggregate function? imagine have following data:

name       |  manual_score 1        |  1 2        |  1 3      |  2 

now, try group elements manual_score , think how show name column corresponds manual_score=1.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -