2017-04-19 4 views
0

クエリを実行すると「エラーコード:不明な列 't2.FSVisitsToDate」が「フィールドリスト」に表示されますが、私のクエリが間違っているところを見つけ出すことはできません。誰もが私が間違って何をしたかを指摘することはできますか?挿入する...重複した更新でフィールドリストに未知の列がありますが、フィールドが存在します

INSERT INTO CMCustomer 
     (CustomerNumber, 
      LastName, 
      FirstName, 
      Address, 
      City, 
      State, 
      ZIPCode, 
      PhoneNo, 
      DriverLicenseNo, 
      SocialSecNo, 
      TaxExempt, 
      ExternalRefNumber, 
      AuxField, 
      Comments, 
      FSLevelNo, 
      FSDateOpened, 
      FSLastVisit, 
      FSVisitsToDate, 
      FSVisitsThisPeriod, 
      FSPurchaseToDate, 
      FSPurchaseThisPeriod, 
      FSDiscountToDate, 
      FSDiscountThisPeriod, 
      FSPointsToDate, 
      FSPointsThisPeriod, 
      FSPromoPointsToDate, 
      FSPromoPointsThisPeriod, 
      LastUpdated, 
      Employee) 
SELECT t1.CustomerNumber, 
      t1.LastName, 
      t1.FirstName, 
      t1.Address, 
      t1.City, 
      t1.State, 
      t1.ZIPCode, 
      t1.PhoneNo, 
      t1.DriverLicenseNo, 
      t1.SocialSecNo, 
      t1.TaxExempt, 
      t1.ExternalRefNumber, 
      t1.AuxField, 
      t1.Comments, 
      t1.FSLevelNo, 
      t1.FSDateOpened, 
      t1.FSLastVisit, 
      t1.FSVisitsToDate, 
      t1.FSVisitsThisPeriod, 
      t1.FSPurchaseToDate, 
      t1.FSPurchaseThisPeriod, 
      t1.FSDiscountToDate, 
      t1.FSDiscountThisPeriod, 
      t1.FSPointsToDate, 
      t1.FSPointsThisPeriod, 
      t1.FSPromoPointsToDate, 
      t1.FSPromoPointsThisPeriod, 
      t1.LastUpdated, 
      t1.Employee 
FROM cm01process t1 
LEFT JOIN CMCustomer t2 ON t2.CustomerNumber = t1.CustomerNumber 
ON DUPLICATE KEY UPDATE   
     t2.FSVisitsToDate = t2.FSVisitsToDate + t1.FSVisitsToDate, 
     t2.FSVisitsThisPeriod = t2.FSVisitsThisPeriod + t1.FSVisitsThisPeriod, 
     t2.FSPurchaseToDate = t2.FSPurchaseToDate + t1.FSPurchaseToDate, 
     t2.FSPurchaseThisPeriod = t2.FSPurchaseThisPeriod + t1.FSPurchaseThisPeriod, 
     t2.FSDiscountToDate = t2.FSDiscountToDate + t1.FSDiscountToDate, 
     t2.FSDiscountThisPeriod = t2.FSDiscountThisPeriod + t1.FSDiscountThisPeriod, 
     t2.FSPointsToDate = t2.FSPointsToDate + t1.FSPointsToDate, 
     t2.FSPointsThisPeriod = t2.FSPointsThisPeriod + t1.FSPointsThisPeriod, 
     t2.FSPromoPointsToDate = t2.FSPromoPointsToDate + t1.FSPromoPointsToDate, 
     t2.FSPromoPointsThisPeriod = t2.FSPromoPointsThisPeriod + t1.FSPromoPointsThisPeriod; 

私が達成しようとしています何私の店のいずれかからファイルを取り、自分のデータベースにインポートすることです。それならば新しい顧客です。行が追加される必要があります。重複した顧客の場合は、更新されたフィールドが必要です(ユーザーにポイントが追加されます)。

+0

あなたの質問に何か問題があるかどうかを確認する必要があります。 –

+0

クエリは既に添付されています。それはコードブロックの中にあります。そこから、左への挿入、重複したキーの更新クエリに挿入されます。 –

+0

私はmysqlのこの機能については熟知していませんが、重複したキー更新ではないはずです FSVisitsToDate = t2.FSVisitsToDate + t1.FSVisitsToDate、... 'なぜt2.FSVisitsToDate'をここに設定しようとしていますか? 。 (再び専門家はいないが、これは間違っていると感じる)。 – JNevill

答えて

0

なぜこれがうまくいったのか分かりませんAIN私はより良い理解を持っているが、私はそうのようなステートメントの「重複した上で...」の部分を構築する場合は明らかに、クエリが正常に完了したので:

ON DUPLICATE KEY UPDATE   
     CMCustomer.FSVisitsToDate = CMCustomer.FSVisitsToDate + values(FSVisitsToDate), 
     CMCustomer.FSVisitsThisPeriod = CMCustomer.FSVisitsThisPeriod + values(FSVisitsThisPeriod), 
     CMCustomer.FSPurchaseToDate = CMCustomer.FSPurchaseToDate + values(FSPurchaseToDate), 
     CMCustomer.FSPurchaseThisPeriod = CMCustomer.FSPurchaseThisPeriod + values(FSPurchaseThisPeriod), 
     CMCustomer.FSDiscountToDate = CMCustomer.FSDiscountToDate + values(FSDiscountToDate), 
     CMCustomer.FSDiscountThisPeriod = CMCustomer.FSDiscountThisPeriod + values(FSDiscountThisPeriod), 
     CMCustomer.FSPointsToDate = CMCustomer.FSPointsToDate + values(FSPointsToDate), 
     CMCustomer.FSPointsThisPeriod = CMCustomer.FSPointsThisPeriod + values(FSPointsThisPeriod), 
     CMCustomer.FSPromoPointsToDate = CMCustomer.FSPromoPointsToDate + values(FSPromoPointsToDate), 
     CMCustomer.FSPromoPointsThisPeriod = CMCustomer.FSPromoPointsThisPeriod + values(FSPromoPointsThisPeriod); 

私はあなたがに挿入されているテーブルを参照することができると思いますあなたが挿入しているテーブルはVALUES()を使用する必要があります誰でも確認できますか?

関連する問題