-1

我正在尝试从特定行的数据更新几行
这是一个单一的表, 我的尝试ItemNum是独一无二的:

UPDATE myTable t, (SELECT DISTINCT width, repeat
            FROM myTable
            WHERE ItemNum='80644') t1
SET t.width = t1.width
AND SET t.repeat = t1.repeat
WHERE ItemNum='80645'
AND WHERE ItemNum='80646'


#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM myTable WHERE ItemNum='80644') t1 SET t.width' at line 2


当我为单行运行它时给我一个错误,
但多行的语法似乎是问题

UPDATE myTable t, (SELECT DISTINCT width
  FROM myTable
  WHERE ItemNum='80644') t1
SET t.width = t1.width
WHERE ItemNum='80645'
4

2 回答 2

0

应该可以,但是如果 itemnum=80644 的行不止一行,它就不会给出可靠的结果

UPDATE myTable t
join
    (SELECT DISTINCT width, repeat
            FROM myTable
            WHERE ItemNum='80644') t1
    on t.ItemNum in ('80645','80646')
SET
    t.width = t1.width,
    t.repeat = t1.repeat  
于 2012-08-06T18:50:45.700 回答
-1
UPDATE t
SET t.width = t1.width
AND SET t.repeat = t1.repeat
FROM  myTable t INNER JOIN  (SELECT DISTINCT width, repeat
            FROM myTable
            WHERE ItemNum='80644') t1
ON ItemNum in ('80645'

,'80646')

update 语句只能有一个表名,它必须更新的表

支持表可以在join中指定,方便更新语句

于 2012-08-06T18:54:04.073 回答