I am new to couchbase and nosql databases. I am trying to figure out how to get the average rating of movies that are above 3. Here is an example how a movie object looks like:
SELECT g.title, ROUND(AVG(r_item.rating),1) AS avg_r
FROM Grouplens_1M AS g
UNNEST ratings r_item
WHERE avg_r > 4.0
GROUP BY g.title
Without the WHERE clause it shows me results. But with the WHERE clause I get an error (Ambiguous reference to field avg_r.). Maybe someone can explain me how to solve this.
Only ORDER BY can reference expression aliased in projection. All other cases the instead of alias repeat the expression, WHERE clause can’t have aggregates if need use HAVING or do parent query.