[英]Best method views by date
I am trying to make a views system for my website.我正在尝试为我的网站制作一个视图系统。
I got a 770 rows of articles in my MySQL database and I'm trying to do a views system to know which article got the most views and when.我的 MySQL 数据库中有 770 行文章,我正在尝试建立一个视图系统,以了解哪篇文章获得最多的观看次数以及时间。 (Today, 3 Days Ago, This week, This month).
(今天,3 天前,本周,本月)。
I tried to do something like this in MySQL database:我试图在 MySQL 数据库中做这样的事情:
Table: views表:视图
ID articleID date
But then I don't know how to sum it up?但是后来不知道怎么总结? and If I will add column 'views' it won't help me because I have to change the dates all time.
如果我要添加列“视图”,它对我没有帮助,因为我必须一直更改日期。
This is the code for any of your view这是您的任何视图的代码
CREATE VIEW purpose AS
SELECT
articleID,
COUNT(articleID) as view_count
FROM views
WHERE date_condition_depending_on_purpose
GROUP BY articleID
PS index on articleID is vital. articleID 上的PS索引至关重要。
All articles:所有文章:
SELECT
COUNT(*) AS number,
articleID
FROM
views
GROUP BY
articleID
ORDER BY
number DESC
2012 only:仅 2012 年:
SELECT
COUNT(*) AS number,
articleID
FROM
views
WHERE
YEAR(date) = 2012
GROUP BY
articleID
ORDER BY
number DESC
For a specific article for each month:对于每个月的特定文章:
SELECT
COUNT(*) AS number,
MONTH(date) AS stats_month,
YEAR(date) AS stats_year
FROM
views
GROUP BY
stats_month,
stats_year
ORDER BY
number DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.