如何根据访问量获得最受欢迎的商品?
假设我们有一个类似这样的项目表,
item_id
item_visits
我们应该向该表添加什么,以便能够根据这些项目在过去 7 天内的访问次数对这些项目进行排序。
我们如何向数据库查询它?
Let's say we have a table for items that looks like this
item_id
item_visits
What should we add to this table, to be able to sort these items based on how many visits they have had in the last 7 days.
And how do we query that to the db?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,我问错了...
嗯,当然,您需要添加一个名为 VisitTime 且类型为 datetime 的列。
之后,我建议创建一组视图来帮助您进行查询。例如,名为 DailyVisit 的视图,其中包含每个项目的日内视图量(由日期表示)。
Sorry, I misunderstood the ask...
Well, of course you need to add a column named VisitTime which has type datetime.
After that I would suggest to create a set of views to help you making the query. For example a view named DailyVisit which has the amount of view in day(indicated by a date) for every item.
你的桌子有点混乱。
您不想跟踪项目访问次数。
您只想跟踪某个项目被访问的时间以及访问者、访问地点以及哪个项目。
我建议如下:
这应该为您提供了解每个项目的访问量并获取有关项目和访客的详细信息所需的所有详细信息。
Your table is a bit confused.
You don't want to keep track of the number of item visits.
You just want to keep track of when an item was visited and maybe by whom and and where and which item.
I would suggest the following:
This should give you all the details you need to know the visits per item and get details about items and visitors as well.