Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 具有多个条件的SQL更新查询_Mysql_Sql - Fatal编程技术网

Mysql 具有多个条件的SQL更新查询

Mysql 具有多个条件的SQL更新查询,mysql,sql,Mysql,Sql,我想就我的问题寻求帮助。我不明白怎么做 我有一个表,其中有一些项目(来自游戏),我需要根据其他项目的值更改它们的displayid列 当我运行此查询时,我有一个 SELECT displayid, name, class, subclass, allowablerace, allowableclass, inventorytype FROM item_template WHERE name LIKE '%S1%'; 我将得到结果-注意这是eq,其中名称包含S1 displayid name

我想就我的问题寻求帮助。我不明白怎么做

我有一个表,其中有一些项目(来自游戏),我需要根据其他项目的值更改它们的displayid列

当我运行此查询时,我有一个

SELECT displayid, name, class, subclass, allowablerace, allowableclass, inventorytype FROM item_template WHERE name LIKE '%S1%';
我将得到结果-注意这是eq,其中名称包含S1

 displayid name                                 class subclass allowablerace allowableclass inventorytype
 39296 Druid S1 Balance Staff                    2       10            -1             -1            17
 39296 Druid S1 Resto Staff                      2       10            -1             -1            17
 31864 Shaman S1 Ele Dagger                      2       15            -1             -1            13
 42376 Shaman S1 Shield                          4        6            -1             -1            14
 31864 Shaman S1 Resto Dagger                    2       15            -1             -1            13
 38679 Warrior S1 Thrown                         2       16            -1             -1            25
--此返回名为的项目包含致命错误

SELECT displayid, name, class, subclass, allowablerace, allowableclass, inventorytype FROM item_template WHERE name LIKE '%Deadly%';

 displayid  name                                         class  subclass  allowablerace  allowableclass  inventorytype 
 55817  Deadly Gladiator's Dreadplate Chestpiece         4         4          32767              32              5 
 55816  Deadly Gladiator's Scaled Chestpiece             4         4          32767               2              5 
 55811  Deadly Gladiator's Plate Chestpiece              4         4          32767               1              5 
 55812  Deadly Gladiator's Plate Gauntlets               4         4     2147483647               1             10 
我的问题是如何为S1项设置致命项DisplayID,其中条件包括相同的类、子类、allowablerace、allowableclass、inventorytype

我试过了,但没用

UPDATE item_template SET displayid = (SELECT displayID FROM item_template c) WHERE inventorytype = c.inventorytype AND class = c.class AND subclass = c.subclass AND allowableclass = c.allowableclass AND name LIKE '%S1%' AND c.name LIKE '%Deadly%';

抱歉英语不好

听起来你想要的是一个更新自连接:

UPDATE item_template it1
INNER JOIN item_template it2
    ON it1.inventorytype = it2.inventorytype AND
       it1.class = it2.class AND
       it1.subclass = it2.subclass AND
       it1.allowableclass = it2.allowableclass
SET
    it1.displayid = it2.displayid
WHERE
    it1.name LIKE '%S1%' AND
    it2.name LIKE '%Deadly%';

听起来您想要的是更新自连接:

UPDATE item_template it1
INNER JOIN item_template it2
    ON it1.inventorytype = it2.inventorytype AND
       it1.class = it2.class AND
       it1.subclass = it2.subclass AND
       it1.allowableclass = it2.allowableclass
SET
    it1.displayid = it2.displayid
WHERE
    it1.name LIKE '%S1%' AND
    it2.name LIKE '%Deadly%';

请参见正确的顺序应首先设置,然后在何处不设置?t1和t2也应该是1,2,但无论如何,谢谢,我一直在寻找。正确的顺序应该先设置,然后在哪里不?t1和t2也应该是,但无论如何,谢谢,我一直在寻找。