Average Reviews per User

Average Reviews per User

Write a query to returns the average number of reviews of movies per user.

What is average number of reviews for all users? (enter an integer number)

Once you executed, enter the value below and click Check Answer.

  • ✓ 149

Hint

Your query should start with:

MATCH (u:User)-[r:RATED]-(m:Movie)
WITH u, count(r) AS NumReviews
WITH collect(NumReviews) AS ReviewCounts

Then add code to UNWIND the list and return the average.

Use toInteger() to return the average as an integer.

What is average number of reviews for all users? (enter an integer number)

Once you have entered the answer, click the Try Again button below to continue.

Solution

You can run the following query to find the answer:

cypher
MATCH (u:User)-[r:RATED]-(m:Movie)
WITH u, count(r) AS NumReviews
WITH collect(NumReviews) AS ReviewCounts
UNWIND ReviewCounts AS x
RETURN toInteger(avg(x))

What is average number of reviews for all users? (enter an integer number)

Once you have entered the answer, click the Try Again button below to continue.

Summary

In this challenge, you wrote a query that used avg() to return the average number of movie reviews per user.

In the next lesson, you will learn about returning minimum and maximum values.