我有每张图片的图像表得到评分
SELECT imagesrc,AVG (rating / total_votes) AS maximumrate FROM imagerate GROUP BY ImageSN order by AVG( rating/total_votes ) DESC LIMIT 1
我获得了Maxmium平均评分图片,但我想要搜索一周的最大评分图片,并且发现下面的代码接近我的要求,但我不能将它们放在一起工作
WHERE time BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)
imagerate structure is
ImageSN (primary key)
imagesrc (imagepath)
time (uploaded at (date))
rating
total votes
需要专家意见帮助!
修改
$requestthree = 'SELECT imagesrc,AVG (rating / total_votes) AS maximumrate FROM imagerate WHERE time >= curdate() - INTERVAL DAYOFWEEK(curdate())+7 DAY
AND time < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY GROUP BY ImageSN order by AVG( rating/total_votes )DESC LIMIT 1';
现在查询给我每周最高评分但是如果我的数据库有两张高AVerage评分图片我想得到哪些图片获得更多票数
我尝试添加
GROUP BY total_votes
因为MAX()会使此查询无效
答案 0 :(得分:2)
上周尝试添加:
SELECT imagesrc,AVG (rating / total_votes) AS maximumrate
FROM imagerate
WHERE time >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND time < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
GROUP BY ImageSN order by AVG( rating/total_votes ) DESC LIMIT 1;