我有一个看起来像的数据库:
id|text|rating|TimeOfRating
用于描述:如果用户对5分中的4分评价,则评分中加4分,并添加TimeOfRating 1。
如何用PHP过滤出评分最高的10条评论?
干杯!
答案 0 :(得分:1)
这会给你平均评分:
SELECT
id,
text,
(rating/TimeOfRating) AS score
FROM tablename
ORDER BY score DESC
LIMIT 10
答案 1 :(得分:0)
根据您提供的信息,这符合您的要求。
SELECT id, text, rating, TimeOfRating
FROM
(SELECT id, text
CASE
WHEN rating = 4 THEN rating + 5
ELSE rating
END AS rating,
CASE
WHEN rating = 4 THEN TimeOfRating + 1
ELSE TimeOfRating
END AS TimeOfRating
FROM pickles) a
ORDER BY rating DESC
LIMIT 10
什么类型的列是TimeOfRating
?