表一:products
具有类似的字段
products_id
products_price
master_categories_id
表二:specials
。此表为空,其中的字段为
specials_id (an autoincrement field)
products_id (the value same as table one)
specials_new_products_price (the value equals products_price-(products_price*0.05))
specials_date_added (the value like this 2011-12-05 12:17:44)
specials_last_modified (the value like this 2011-12-05 12:19:10)
expires_date (2011-12-31)
date_status_change (the value like this 2011-12-05 12:19:10)
status (1)
specials_date_available (2011-11-29)
现在,我想插入数据
("SELECT products_id,products_price FROM products where master_categories_id=79")
into table 2. and set the `status=1, specials_date_available=2011-11-29,
expires_date=2011-12-31`.`products_id(the value same as table one)
specials_new_products_price (the value equals products_price-(products_price*0.05))
其余字段的值由您决定。
我认为这是不好的方式,写一个php文件来进行插入。选择products id、products price,然后将它们一行接一行地放在txt文件中,然后将文件内容放在表2中。但我不知道如何将文本文件数据放入表2中,以及如何设置其余字段的值?
insert into specials
(products_id, products_price,status,specials_date_available,expires_date)
SELECT products_id,products_price*0.95 as products_price,
1, '2011-11-29', '2011-12-31'
FROM products where master_categories_id=79
或者类似的东西。