2016-10-10 7 views
1

私はここで私の結果を得ることができるユニオンを使用して手の数を表示するために私のクエリを得た。 allinvty3は私のユニオンの結果に基づいて私のアイテムの数量を更新したい私のマスターファイルです。 allinvty3可変出力に基づいて$合計に基づいて更新することが可能ですか?PHP/MYSQL - ユニオンを使ってサブクエリを更新する

**My table :** 


    |allinvty3|(masterfile) 
     ---------------- 
     |in_code  | 
     |ecr_desc  | 
     |pric_cash 
     |qty   | 
     |ite_desc  | 
     --------------- 

|barcode, branchtobranch,adjustment table(all tables have same fieldnames) | 
     ---------------- 
     |itemcode  | 
     |qty   | 
     |status  | 
     --------------- 

これは私の連合のための私のサンプル出力である私のマスターファイルであるすべてのiは、データを取得したいとallinvty3で私の数量を更新することができ

This is my sample output for my Union all and i want to get the data and able to update my quantity in allinvty3 which is my masterfile これはすべての私の連合のための私のサンプル出力です私のすべてのフィールドが正しいにもかかわらず、私は、私はちょうど以下の提案のように更新したときに、私のマスターファイル

$sql = "UPDATE allinvty3 as A, (
    select 
     ite_desc,ecr_desc, pric_cash, t.itemcode as itemcode ,sum(t.qty) as qty 
    from ( 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from barcode as bc inner JOIN allinvty3 as ait on bc.itemcode = ait.in_code 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from branchtobranch_tb as bb inner JOIN allinvty3 as ait on bb.itemcode = ait.in_code 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from adjustment_tb as adt inner JOIN allinvty3 as ait1 on adt.itemcode = ait1.in_code where adt.status='APPROVED' 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from stockreturn_tb as sb inner JOIN allinvty3 as ait on sb.itemcode = ait.in_code 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from notinclude_tb as nt inner JOIN allinvty3 as ait on nt.itemcode = ait.in_code where nt.status='COMPLETE' 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from purchase_tb as pt inner JOIN allinvty3 as ait on pt.itemcode = ait.in_code 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,(qty * -1) from soldout_dm as slp inner JOIN allinvty3 as ait2 on slp.itemcode = ait2.in_code 
    ) as t 
) as UD 
SET 
    A.sa_onhand = UD.qty 
WHERE 
    A.in_code = UD.itemcode"; 



$result = $conn->query($sql); 

エラーであるallinvty3で私の数量を更新することができるデータとを取得したい

お知らせ:非オブジェクト

+0

テーブル構造とサンプルデータを共有してください。 –

+0

@TeKo、私は自分のデータを共有しました。 – codeSeven

答えて

1

のプロパティを取得しようとすると、私はあなたがこのようにこれを行うに使用することができると思う:MySQLのhereでSELECTまたはhereからUPDATES当接し

UPDATE allinvty3 A, (
    select 
     ite_desc,ecr_desc, pric_cash, t.itemcode as itemcode ,sum(t.qty) as qty 
    from ( 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from barcode as bc inner JOIN allinvty3 as ait on bc.itemcode = ait.in_code 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from branchtobranch_tb as bb inner JOIN allinvty3 as ait on bb.itemcode = ait.in_code 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from adjustment_tb as adt inner JOIN allinvty3 as ait1 on adt.itemcode = ait1.in_code where adt.status='APPROVED' 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from stockreturn_tb as sb inner JOIN allinvty3 as ait on sb.itemcode = ait.in_code 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from notinclude_tb as nt inner JOIN allinvty3 as ait on nt.itemcode = ait.in_code where nt.status='COMPLETE' 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,qty from purchase_tb as pt inner JOIN allinvty3 as ait on pt.itemcode = ait.in_code 
     union all 
     select ite_desc,ecr_desc, pric_cash, itemcode,(qty * -1) from soldout_dm as slp inner JOIN allinvty3 as ait2 on slp.itemcode = ait2.in_code 
    ) 
    group by itemcode order by ecr_desc ASC 
) UD 
SET 
    A.qty = UD.qty 
WHERE 
    A.itemcode = UD.itemcode 

より。

+0

私はお試しください。助けてくれてありがとう、私はqyuが誤植だと思う? @ T.Z。 – codeSeven

+0

はい。私は答えを修正した。 :) –

+0

本当にありがとうございましたが、「オブジェクト以外のプロパティを取得しようとしています」というエラーがあります。私のフィールド名は正しいが。 ( – codeSeven

関連する問題