2011-12-05 7 views
0

表1:specialsデータベース内の別のテーブルを使用してテーブルレコードを更新するにはどうすればよいですか?

products_id 
products_price 
master_categories_id 

表2のようなフィールドがありproducts。このテーブルには、それは、今

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を選択し、次に1行ずつtxtファイルに入れてから、ファイル内容を表2に入れます。ただし、テキストファイルのデータをtable2に配置する方法と、残りのフィールド値?

答えて

0
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 

などです。

+0

申し訳ありませんが、あなたのsqlコマンドの使い方はわかりません。これらのフィールドの値を設定する方法specials_date_added date_status_change specials_last_modified – down321

+0

通常、SQLコマンドは実行時に使用されます。もちろん、まずそれを把握する必要があります。文字列値を含むクエリの結果を名前列のリストとしてスペシャルに挿入します。今私はそれを説明したことがありません*あなたのために*それを理解することはほとんどありません:) –

+0

SQLコマンドでproducts_price specialsテーブルへの挿入は私が欲しいものではありません、私はそれが値products_price-(products_price * 0.05)としたいです – down321

関連する問題