Skip to content
Advertisement

How do I remove results based on conditions to calculate an average

I have the schema below. A quick explanation of it is:

  1. bob rated up 5/5
  2. james rated up 1/5
  3. macy rated up 5/5

The logic:

  1. If I am personA, look up everyone I have blocked.
  2. Look up all the movie reviews.
  3. Anyone who has left a movie review, and personA has blocked, remove them from the calculation.
  4. Calculate the average rating of the movies.

I don’t understand how I can get rid of reviews if its on a block list

When I view the database as bob, I should get:

When I view the database as macy, I should get:

Advertisement

Answer

I don’t know how to express your logic without using an exists clause. I might try here:

Note that we want to aggregate by movie name, so we need GROUP BY here. The exists clause says to exclude from the average rating any review for which we can find a blocked entry belonging to a certain customer (in this case, cus_id = 1).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement