mysql传输查询

时间:2012-04-04 17:56:34

标签: mysql

我更新了我的程序处理罚款和收费的方式,现在我需要将旧数据传输/迁移到新格式。过去工作的方式是罚款/收费存储在用户记录的字段中。现在有一个全新的表用于跟踪每次充电。我想简单地将该费用字段和1条记录带到该计费表中。

User table: id as INT, name as VARCHAR, charges as DECIMAL(10, 2)
Charge Table: id as INT, user_id as INT, amount as DOUBLE, type as INT, date_applied as DATETIME, description as VARCHAR

假设我有一个用户记录:(id => 1, name => 'john doe', charges => 4.20)并希望将其转移到

的费用记录中
(id => 1, user_id => 1, amount => 4.20, type => 1, date_applied => (whatever  time the transfer is taking place), description => 'Initial balance')

如何在SQL查询中进行一次转移?我不想为这次一次性交易写一个PHP脚本。

1 个答案:

答案 0 :(得分:2)

这应该做你想要的。

INSERT INTO `Charge Table` SELECT NULL, id, charges, 1, NOW(), 'Initial balance' FROM `User Table`