简体   繁体   English

如何使用数据库中的另一个表更新表记录?

[英]How to update a table record using another table in a database?

Table one: products Which have fields like 表一:具有类似字段的products

products_id
products_price
master_categories_id

Table two: specials . 表二: specials This table is empty,Fields in it are 该表为空,其中的字段为

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)

now, i want to insert the data 现在,我想插入数据

("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)) 

the rest field's value is up to you. 其余字段的值取决于您。

the way that i think which is not good ,write a php file to do the insert. 我认为这不好的方式,写一个PHP文件做插入。 select out the products_id,products_price , then put them in a txt file one line after another, then put the file content into the table 2. but i don't know how to put the text file data into the table2 and how to set the rest fields value? 选择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

or something like that. 或类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM