Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Average ratings table

$
0
0

I have a table which captures the ratings from 100s of products as below

Ratings table: Id, ProductID, Rating(decimal)

Data would look like

ID -  ProductID - Rating
1  -        2        -    2
2  -        2        -    5
3  -        2        -    4.5
4  -        10        -    3
5  -        10        -    1

So the average for ProductID 2 would be 3.83.

My application would have a control on a webpage which would allow the user to select the rating value number of 1,2,3,4 or 5.

Rounding would be enabled so 3.83 would be 4

If i want to return all products with rating 4 (selected by the user on a page for example) then i have some calculation to do i.e.get each product, pass that product ID into a function to get the average rating, round it and then display it on my page.

If i get thousands of products or even thousands of reviews i feel this may become a performance issue.

Is there a better way to design my tables so that i could get the average ratings in a more better manner?


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>