且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL在某些条件下插入行的问题

更新时间:2023-12-02 08:03:04

我认为唯一的问题是在第二行,删除FROM test ..您不能select 6, 50 from test .. 6和50不是测试中的列,并且测试没有记录.像这样尝试:

I think the only thing wrong with this is on line two, remove FROM test.. You can't select 6, 50 from test.. 6 and 50 are not columns in test, and test has no records. Try it like this:

INSERT IGNORE INTO test (id, amount) 
SELECT * from (select 6, 50) as a 
WHERE NOT EXISTS (SELECT 1 FROM test 
                  WHERE amount >= 50 AND id = 6)