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
Post a Comment