我正在为 iPhone 应用程序创建视频的趋势提要,并在视图表中计算过去 24 小时内视频的所有视图(每次视图时都会将一行添加到视图表中,并且具有时间戳和 videoid )。当我对其进行无限滚动时,我会发回最后一个视频观看次数,并使用 mySQL 中的 HAVING 语句来获取下一个视频
"HAVING COUNT(views.videoid) < 'count of views'" with a "LIMIT 10"
最后一次选择10。
这可行,但是如果一个视频在过去 24 小时内与另一个视频的观看次数相同,那么该视频可能会被跳过,因为它是一个 < 语句。如果我使用 <= 语句,视频将多次显示。
有没有办法让我在 videoid 之后选择视频
"ORDER BY COUNT(views.videoid) DESC"
获取下一个视频?可能不会,但有人知道我会怎么做。这是我的查询。
SELECT f.userid, f.username, video.videoid, video.videolink, video.timestamp, video.caption, video.tags, video.address, video.likecount, video.commentcount, video.viewcount, video.shareid, CASE WHEN liketable.likekey > 0 THEN 1 ELSE 0 END AS didlike, COUNT(views.videoid) AS trendcount
FROM user AS f
RIGHT JOIN video ON video.userid = f.userid
LEFT JOIN user ON user.token = ?
LEFT JOIN liketable ON liketable.videoid = video.videoid AND liketable.userid = user.userid
RIGHT JOIN views ON views.videoid = video.videoid
WHERE views.timestamp > ?
GROUP BY video.videoid
HAVING COUNT(views.videoid) < ?
ORDER BY COUNT(views.videoid) DESC
LIMIT 10