drxkx6149 2018-05-18 15:10
浏览 19
已采纳

本周流行 - 本月流行 - PHP功能

Suppose a table videos

id        | name         | views
----------+--------------+-----------
1         | Video1       | 52
2         | Video2       | 150
...

For getting the video which is popular/most viewed this week, I could create another table: videoviews

id        | foreign_key  | viewed_on
----------+--------------+-----------
1         | 1            | 10/12/2018
2         | 1            | 09/12/2018
...

From this table, I can easily get the data for last week/last month etc. That's not an issue.

Problem: Suppose I have 1000 Videos and Each video gets 100 Views per day. My videoviews table will have 100000 records each day.

I know this is not the best way to achieve this functionality. Just wondering what is?

I found these on SO but..

How to get most visited posts of the week?

Popular Today, This Week, This Month - Design Pattern

  • 写回答

2条回答 默认 最新

  • dongzao9044 2018-05-18 15:19
    关注

    Problem: Suppose I have 1000 Videos and Each video gets 100 Views per day. My videoviews table will have 100000 records each day.

    Do you need a complete record of each individual view?

    You could, instead, use a counter approach, where you store one row per video per day, and simply increment its value when a new row comes in. This is granular enough to provide useful per-day analytics, without having to store a million rows for a million video views.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!