如何将日常记录从 mysql 表存储到另一个表? [英] How to store day to day records from a mysql table to another?
问题描述
朋友 我创建了一个 mysql 表来获取我网站的页面访问量.我的桌子是这样的
Friends I have created a mysql table to get the page visits for my website. My table is like this
statistics_table(stat_id,visited_page,visit_count)
visit_count 每次访问都会增加 1.这很完美.但现在我需要每天将所有统计数据保存在不同的表中,以达到我的流量监控目的.
Where the visit_count is incrementing by one for every visit.This works perfect. But now i need to to save all statistics in a different table each an every day to my traffic monitoring purpose.
喜欢以下
2012/12/15-->page1-->100 visits
2012/12/16-->page1-->180 visits
2012/12/17-->page1-->200 visits
因为 statistics_table 每天都在增加它的值,所以我可以使用
because statistics_table incrementing its value every day,so i can get how many visits per day using
(2012/12/16-->page1-->visits)-(2012/12/15-->page1-->visits)//80 visits
目前我正在使用另一个具有相同 schema+date
的表,并每天使用 cron 作业更新它.
At the moment i am using an another table with same schema+date
and update it everyday using cron job.
有什么办法可以使这项工作而不是我的方式?我的意思是简单/更好的方法来做到这一点.感谢您的建议.
Is there any way to make this work rather than my way? I mean easy/better way to do this.Thanks for any advice.
推荐答案
可以使用下面的查询语句将数据插入到另一个表中,
You can use the following query statement to insert datas to another table,
INSERT INTO Table_name(stat_id,visited_page,visit_count)
SELECT stat_id,visited,visit_count_page FROM Exist_Tablename WHERE <condition>;
DELETE FROM Exist_Tablename
WHERE <condition>;
这样你可以试试,
这可能对您有所帮助.
这篇关于如何将日常记录从 mysql 表存储到另一个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!