1

これは私の正確なSQLコードですが、非常に遅く、ひどいことを知っています...

これを行う別の方法はありますが、より高速ですか?

UPDATE Customer SET Title = "MR", SurName = "Test", FirstName ="Bob", HomePostCode ="SW18" WHERE CustomerID IN (SELECT CxID FROM Production WHERE policy_number = "001C5T" AND member_number = "100" AND family_group = "000001" AND CxID > 0)

ありがとう

4

5 に答える 5

3

これを試してください(テストされていません)

UPDATE Customer c
JOIN Production p ON p.CxID = c.CustomerID
SET c.Title = "MR",
    c.SurName = "Test",
    c.FirstName ="Bob",
    c.HomePostCode ="SW18"
WHERE p.policy_number = "001C5T"
    AND p.member_number = "100"
    AND p.family_group = "000001"
    AND p.CxID > 0
于 2012-07-03T13:55:31.570 に答える
1

私はあなたがこのようなものが欲しいと思います:

UPDATE customer 
SET Title = "MR", SurName = "Test", FirstName ="Bob", HomePostCode ="SW18" 
FROM customer    
inner join production on customer.customerID = production.cxid 
where policy_number = "001C5T" AND member_number = "100" AND family_group = "000001" AND CxID > 0
于 2012-07-03T13:55:33.847 に答える
1

krakoverの答えを拡張するために、次のテーブルに参加できます。

UPDATE Customer JOIN 
Production P ON (C.CustomerID = P.CxID) 
AND (P.policy_number = "001C5T") 
AND (P.member_number = "100") 
AND (P.family_group = "000001") 
AND (P.CxID > 0)  
SET C.Title = "MR", C.SurName = "Test", C.FirstName ="Bob", C.HomePostCode ="SW18"

シェマに応じて、テーブルのエイリアスを再確認してください。

于 2012-07-03T13:56:13.393 に答える
1

アップデートでテーブルを結合できるため、副選択はありません。

于 2012-07-03T13:49:12.513 に答える
0

JOINを使用しない別のアプローチ:

INSERT INTO Customer (CustomerID, Title, SurName, FirstName, HomePostCode)
SELECT CxID, 'MR', 'Test', 'Bob', 'SW18'
FROM Production
WHERE policy_number = '001C5T' AND member_number = '100' AND family_group = '000001' AND CxID > 0
ON DUPLICATE KEY UPDATE Title = VALUES(Title), SurName = VALUES(SurName), FirstName = VALUES(FirstName), HomePostCode = VALUES(HomePostCode)

これには、少なくとも1つの一意の列が必要です。これはCustomerIDだと思います。

于 2012-07-03T14:01:36.000 に答える