0

我创建了以下 SQL 代码来迁移我们的数据库。UP 查询工作正常,但我不知道如何修复 DOWN 查询。我只想插入 payment_gateway 表中的所有数据,但也必须匹配正确的 reseller_shop.id。

// UP
INSERT INTO payment_gateway (`type`, account, keyIn, keyOut, resellerShopId)
SELECT 'paymentGatewayOgone', rs.ogoneAccount, rs.ogoneSignatureIn, rs.ogoneSignatureOut, rs.id
FROM reseller_shop AS rs
WHERE rs.ogoneAccount <> '';

// DOWN
INSERT INTO reseller_shop (ogoneAccount, ogoneSignatureIn, ogoneSignatureOut)
SELECT pg.account, pg.keyIn, pg.keyOut
FROM payment_gateway AS pg
WHERE pg.type = 'paymentGatewayOgone'
AND reseller_shop.id = pg.resellerShopId
4

3 回答 3

2
INSERT INTO reseller_shop (ogoneAccount, ogoneSignatureIn, ogoneSignatureOut)
SELECT pg.account, pg.keyIn, pg.keyOut FROM payment_gateway AS pg 
WHERE pg.type = 'paymentGatewayOgone' AND  pg.resellerShopId in 
(select reseller_shop.id from reseller_shop_id)

希望这可以帮助

于 2013-01-31T11:49:20.093 回答
2

似乎我不得不使用 UPDATE 而不是 INSERT INTO。

UPDATE reseller_shop AS rs, payment_gateway AS pg
SET rs.ogoneAccount = pg.account, rs.ogoneSignatureIn = pg.keyIn, rs.ogoneSignatureOut = pg.keyOut
WHERE pg.type = 'paymentGatewayOgone'
AND rs.id = pg.resellerShopId
于 2013-01-31T12:01:06.050 回答
0

像这样的一些事情:

INSERT INTO reseller_shop (ogoneAccount, ogoneSignatureIn, ogoneSignatureOut)
SELECT pg.account, pg.keyIn, pg.keyOut
FROM payment_gateway AS pg 
    INNER JOIN reseller_shop AS rs ON  rs.id = pg.resellerShopId
WHERE pg.type = 'paymentGatewayOgone'

或者:

INSERT INTO reseller_shop (ogoneAccount, ogoneSignatureIn, ogoneSignatureOut)
SELECT pg.account, pg.keyIn, pg.keyOut
FROM payment_gateway AS pg 
WHERE pg.type = 'paymentGatewayOgone' 
    AND EXISTS (SELECT * 
                FROM reseller_shop AS rs 
                WHERE rs.id = pg.resellerShopId)
于 2013-01-31T11:51:30.137 回答