立即将数据插入到表中,从mySQL select命令中检索

时间:2015-05-17 18:19:16

标签: php mysql

我已经提到了我的原始事务表和临时事务表我想将数据插入临时事务表,我选择了事务表的值

    CREATE TABLE Transaction(
    Tid int auto_increment primary key,
    T_type varchar(20),
    Amount decimal(10,2),
    Tdate DATETIME,
    accountNo int,
    CONSTRAINT FOREIGN KEY(AccountNo) REFERENCES Account(AccountNo)
    ); 



CREATE TABLE tempTransaction(
    Tid int auto_increment primary key,
    T_type varchar(20),
    Amount decimal(10,2),
    Tdate DATETIME,
    accountNo int,
    CONSTRAINT FOREIGN KEY(AccountNo) REFERENCES Account(AccountNo)
    );
  

我想编辑此查询以使用一个那是我的问题

INSERT INTO temporarytransaction VALUES (SELECT * FROM Transaction WHERE `Tdate` BETWEEN "2012-03-15" AND "2016-03-31"); 

2 个答案:

答案 0 :(得分:0)

不要将values()放入; http://dev.mysql.com/doc/refman/5.6/en/insert-select.html

INSERT INTO temporarytransaction SELECT * FROM Transaction WHERE `Tdate` BETWEEN "2012-03-15" AND "2016-03-31";

答案 1 :(得分:0)

试试这个:

generator