简体   繁体   English

用户评论的数据库架构

[英]Database schema for user reviews

I am working on user reviews with this columns: 我正在使用此列进行用户评论:

  • product_id product_id
  • communication 通讯
  • cleanliness 清洁度
  • location 位置
  • value

Each column can be number from 1-5. 每列可以是1-5的数字。 My question is how to calculate average grade for each column with out calling all reviews from database and calculating it every time. 我的问题是如何在不调用数据库中的所有评论并每次计算的情况下如何计算每列的平均成绩。

So I was thinking to put in product table: 所以我当时想放在产品表中:

  • communication_sum_of_grades communication_sum_of_grades
  • communication_number_of_reviews communication_number_of_reviews
  • ... etc ...等等

and than do: average= communication_sum_of_grades / communication_number_of_reviews 比做:average = communication_sum_of_grades / communication_number_of_reviews

My question is if this is right approach? 我的问题是这是否正确?

If there are large number of records and query for average reviews are very frequent then your method will be efficient because in this case writing will be a touch heavy but reading will be very fast . 如果有large number of records并且查询平均审阅very frequent那么您的方法将很efficient因为在这种情况下,书写会很touch heavy but reading will be very fast But in case the query for average reviews is not that frequent then you may go for the triditional method of fetching all rows and finding avarage. 但是,如果对平均评论的查询不是那么频繁,那么您可以使用一种获取所有行并查找平均的传统方法。

hope it helps :) 希望能帮助到你 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM