在oracle中使用group by不是count(*)而是min()函数

时间:2013-11-06 21:54:39

标签: sql oracle oracle10g

如何对3列使用group by,它显示的错误是它不是按表达式分组。 这是查询。

select
   brewer.name as brewer,beer.name as beer,count(ratings.score) as LowestRating
from ratings,beer,brewer
where ratings.beer=beer.id and beer.brewer=brewer.id
group by brewer,beer; 

1 个答案:

答案 0 :(得分:1)

您应该GROUP BY按列,而不是整个表:

select
     brewer.name as brewer,
     beer.name as beer,
     count(ratings.score) as LowestRating
  from
    ratings,
    beer,
    brewer
where
  ratings.beer = beer.id
  and beer.brewer = brewer.id
group by brewer.name, beer.name;