SQL 查询查找趋势
我有两个表 - 投票和污点。 投票有名称、时间和喜欢/不喜欢参数作为表列。印记只是人们投票选出的一些标签。他们有一个分数(喜欢减去不喜欢)和 number_of_votes 作为字段。
我整理了一个查询来查找趋势污点 -
SELECT name, number_of_votes, score FROM `vote`
INNER JOIN `blote` ON vote.name=blote.name
WHERE UNIX_TIMESTAMP(now()) - `time` < 60*60*24*7
GROUP BY vote.name
ORDER BY blote.number_of_votes DESC
LIMIT 25
这显然是错误的。它会找到那些在上周拥有更多选票且至少拥有一票的 Blotes。我想要的是找到上周获得更多选票的人。希望这是有道理的。谢谢。
I have two tables - votes and blotes.
Votes have a name, time and like/dislike parameter as table columns. Blotes are just some tags people voted for. They have a score (likes minus dislikes) and number_of_votes as fields.
I put together a query to find trending blotes -
SELECT name, number_of_votes, score FROM `vote`
INNER JOIN `blote` ON vote.name=blote.name
WHERE UNIX_TIMESTAMP(now()) - `time` < 60*60*24*7
GROUP BY vote.name
ORDER BY blote.number_of_votes DESC
LIMIT 25
Which is apparently wrong. It finds those Blotes which have more votes and at least one vote in last week. What I want is to find those which have more votes in last week. Hope it makes sense. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有时写一个问题很有帮助。我知道我需要使用 count(),提交问题后不久,我就知道了如何做到这一点。
这是:
有什么方法可以改进这个查询吗?
Sometimes it helps a lot to write a question. I knew I need to use count(), and few moments after submitting a question, I saw how to do it.
Here it is:
Any way to improve this query?