A normalized database of movie ratings might look like this:

A web page might execute the following two queries to display the movie’s information:
select title
from movies
where id = 12345;
select avg(rating) as rating
from ratings
where movie_id = 12345;
To squeeze out a little better performance, the database could be denormalized a bit, and the average rating for the movie could be stored along with the movie. This would result in a performance increase because you wouldn’t have to hit the ratings table to retrieve the movie’s rating.

Then you could select the movie’s rating along with the title and whatever else.
select title, rating
from movies
where id = 12345;
You just have to remember to update the movie’s rating every time a user rates it:
update movies
inner join ratings on (movies.id = ratings.movie_id)
set movies.rating = avg(ratings.rating);
However, let’s say you have a very large user base, so the ratings table has a billion or so records. Also, you want the rating process to be as quick as possible, so every millisecond counts. Further, you are processing thousands of simultaneous requests, so you can’t waste any CPU power. You might find this model more appealing. In this scenario, the components of the average are stored in the movies table, and they are incremented each time a movie is rated.

The SQL to retrieve the average is below. The difference in performance is negligible.
select title, sum_rating/count_rating as rating
from movies
where id = 12345;
However, the improvement comes when a movie is rated. The SQL below is faster than the previous method because you don’t have to hit the ratings table in order to rate a movie. Keep in mind: you’ll have to rate a billion movies to notice the improvement.
update movies set
sum_rating = sum_rating + 3
, count_rating = count_rating +1
where movie_id = 12345;
As with all performance testing and tweaking, you need real data and real people. If you compare these three methods to a small database with a few thousand rows using a powerful development computer with one user, you’ll find that there is no difference between them. However, if you have millions of records and dozens of simultaneous users, the second method becomes noticeably faster than the first. When you reach the billion record mark and have thousands of simultaneous users, then you see the third has advantages over the second.