[英]How to update a table record using another table in a database?
表一:具有类似字段的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中。但是我不知道如何将文本文件数据放入table2中以及如何设置其余字段的价值?
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
或类似的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.