0

2 つのテーブル A と B があり、両方のテーブルが同じです。今日、テーブル A にいくつかの値を挿入し、挿入されたすべてのテーブル A のデータを 2 日後にテーブル B に自動挿入したい場合。たとえば、今日は 2013 年 6 月 15 日で、テーブル A のすべてのデータは 2013 年 6 月 17 日に自動的にシフトされます。

スクリプトを教えてください。

前もって感謝します。

4

4 に答える 4

2

You'll need to add a timestamp field to your rows in Table A, then you can do this:

insert into b (select * from A where datediff(curdate(), postdate)>=2)

where postdate is your timestamp.

To automate this you can use the mySQL event scheduler (see CREATE EVENT for the syntax) if it's enabled on your server, or use a cron job as suggested elsewhere

于 2013-06-15T07:44:17.967 に答える
1
insert into tableb select * from tablea;

完全なドキュメントはこちら

于 2013-06-15T07:51:42.807 に答える
0

多分あなたは次のようなものを探しています:

CREATE TABLE tableB LIKE tableA;
于 2013-06-15T07:34:29.627 に答える
0

すでに述べたように、これの SQL コードは「insert into b (select * from A)」です。

これを自動的に呼び出すには、小さな PHP-Cronjob を作成し、これをサーバーの crontab に追加して、x 分/時間/日ごとに実行させます (必要なもの)。

于 2013-06-15T07:37:15.263 に答える