How to store day to day records from a mysql table to another?

前端 未结 2 1712
梦如初夏
梦如初夏 2021-01-26 14:46

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)
相关标签:
2条回答
  • 2021-01-26 15:22

    I agree with the answer above, but I recommend that you use MySQL events. See CREATE EVENT in the MySQL manual for more details.

    In summary, your event should be:

    CREATE EVENT myevent
        ON SCHEDULE Every Day
        DO
          INSERT INTO Table_name(stat_id,visited_page,visit_count)
          SELECT stat_id,visited,visit_count_page FROM Exist_Tablename WHERE date_field =          
          DATE_SUB(CURDATE(), INTERVAL 1 DAY);
    
    DELETE FROM Exist_Tablename 
    WHERE date_field = DATE_SUB(CURDATE(), INTERVAL 1 DAY);
    
    0 讨论(0)
  • 2021-01-26 15:25

    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>;
    

    Like this you can try,

    This may helps you.

    0 讨论(0)
提交回复
热议问题