我正在创建一个数据库来保存用户的照片,并将返回每天最多的点赞照片<也是每个月的,year>示例:我创建了一张照片A,第一天,我得到了100个赞,第二天,我得到了200个赞,我总共有300个赞,所以我必须存储每天的点赞值。我在想像这样的结构:
Table Photo[photo_id, user_id, photo_url]
Table Day_Rating[id, photo_id, like_count, date]
//Photo A can have many records in this table
Table Month_Rating[id, photo_id, like_count, month] //month is: 1,2,3,4..12
//Photo A can have many records in this table因此,当用户喜欢一张照片时,我们将在Day_Rating和Month_Rating表的like_count字段上加1。因此,为了获得每日评级,我们将在Day_Rating表上获得与like_count最多的点赞,月度评级也是如此。你对这种方法有什么看法?如果有更好的做法,你能告诉我一个最好的做法吗?谢谢
发布于 2015-08-21 20:04:13
您只需使用两个表即可完成所有需要的操作:
photo
* id
* posted_by_user_id
* url
rating
* id
* photo_id
* rated_by_user_id
* rated_at
* rate然后让数据库引擎进行聚合。另外,单独存储每个评分将允许您执行“每个用户只有一个评分”等规则,并允许用户撤销他们的投票。
https://stackoverflow.com/questions/32139624
复制相似问题