SQL查询:游戏服务器。如果我打破查询,它的工作原理。如果我把它们放在一起,就会失败

时间:2013-01-24 00:52:43

标签: sql sql-insert

查询是:

插入char_inventory(charid,location,slot,itemid,quantity)值(从chars中选择charid,其中charid不在(从char_inventory中选择charid,其中itemid = 65535),0,0,65535,10000);

3 个答案:

答案 0 :(得分:0)

INSERT INTO...SELECT

中使用LEFT JOIN语句
INSERT INTO char_inventory (charid, location, slot, itemid, quantity) 
SELECT  chars.charid, 0 , 0, 65535, 10000
FROM    chars
        LEFT JOIN char_inventory
            ON  chars.charid = char_inventory.charid AND
                char_inventory.itemid = 65535
WHERE   char_inventory.charid IS NULL

答案 1 :(得分:0)

这个怎么样

insert into char_inventory (charid,location,slot,itemid,quantity) 
select charid,0,0,65535,10000 from chars where charid not in (select charid from char_inventory where itemid=65535)

答案 2 :(得分:0)

请改为尝试:

insert into char_inventory (charid,location,slot,itemid,quantity)
    select charid,0,0,65535,10000
    from chars
    where charid not in (select charid from char_inventory where itemid=65535)