情景是数据库里有一系列的post(新闻类),现在想根据post表中有的post_date(时间),view(浏览数量),或者post_like表的likeCount进行排序,并分批读取数据,limit在25
比如说post_date:
SELECT post.*, user.user_avatar, user.user_name,
(SELECT COUNT(*) FROM comment
WHERE comment.post_id = post.post_id) AS commentCount,
(SELECT COUNT(*) FROM post_like
WHERE post_like.post_id = post.post_id) AS likeCount
FROM post, user where post.user_id=user.user_id and post.post_date < "2018-04-05 12:12:35" order by post.post_date desc limit 25
这里post_date可以抓取最后一条的post_date用来做下次获取的标记值。
但是问题是:如果我想通过view或者likeCount排序分批读取数据,获取的数据中没有可以用来做标记,拿来进行下次对比的标记值。
mysql语句如下:
SELECT post.*, user.user_avatar, user.user_name,
(SELECT COUNT(*) FROM comment
WHERE comment.post_id = post.post_id) AS commentCount,
(SELECT COUNT(*) FROM post_like
WHERE post_like.post_id = post.post_id) AS likeCount
FROM post, user where post.user_id=user.user_id order by likeCount desc limit 25
大家一般都是怎么解决的?谢谢