如何计算派生率和使用php / mysql传递给它的订单用户

时间:2016-12-21 05:12:57

标签: php mysql phpmyadmin

我想从与他的个人资料相关的所有评论计算用户平均费用,并将其打印在他的个人资料页面中,也在我想要计算费率的所有用户的类别页面中打印并打印并订购用户Descending传递在avrage评级值。

我的架构是:

UserAccount (id, category_id, name, description, IMGlogo, video)
Comment (id, User_id, name, body, email, date, **rating**)

怎么样?

1 个答案:

答案 0 :(得分:0)

SELECT AVG(rating) AS average_rating
  FROM Comment
 WHERE User_id = ?;

SELECT ua.id, ua.name, AVG(c.rating) AS average_rating
  FROM UserAccount ua
  JOIN Comment c ON c.User_id = ua.id
 WHERE ua.category_id = ?
 GROUP BY ua.id
 ORDER BY average_rating DESC;