[英]calculate the average rating on a review system
需要在評論系統上計算平均評分
我的評論有3個項目: comfort
, price
, clean
-允許介於0和5之間
INSERT INTO review (id, comfort, price, cleanliness) values (1, 3, 5, 2); INSERT INTO review (id, comfort, price, cleanliness) values (2, 2, 4, 4);
當我列出評論的內容時,我將必須計算每個項目的平均值...
我最好將媒體保存在單獨的表中,以避免每次都要計算?
insert into company (id, rate_ comfort, rate_ price, rate_ cleaning, description) values (1, 3, 5, 3, 'text description');
SELECT AVG(comfort), AVG(price), AVG(cleanliness)
FROM review
才是您真正需要的。 沒有任何分組/ where子句,將為表中的所有記錄計算平均值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.