0
我收到錯誤「錯誤代碼:未知列‘t2.FSVisitsToDate’在‘字段列表’當我跑我的查詢,但我無法揣摩出我的查詢是錯誤的。任何人都可以指出我做錯了什麼?INSERT INTO ...上的重複更新導致字段列表未知列,但該領域存在
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;
我試圖做到的是從我的商店之一採取文件,並將其導入到我的數據庫。如果是一個新的客戶,我需要添加的行,如果它是一個重複的客戶,我需要更新的字段(加分的用戶)。
你需要證明你的查詢我們必須在看到有什麼不對您的查詢的機會。 –
該查詢已附加。它正好在代碼塊中,插入..從..左連接..在重複密鑰更新查詢。 –
我在MySQL的這個功能沒有專家,但它不應該是'對重複密鑰更新 FSVisitsToDate = t2.FSVisitsToDate + t1.FSVisitsToDate,...'你爲什麼想在這裏設置't2.FSVisitsToDate' 。 (再次沒有專家,但這種感覺不對)。 – JNevill