gpt4 book ai didi

mysql - 如果 MySQL 中的表中不存在则插入记录失败

转载 作者:行者123 更新时间:2023-11-29 20:03:34 26 4
gpt4 key购买 nike

这是我的查询:

INSERT INTO table (id, actions, date, comments, type, url, rating)
SELECT * FROM (SELECT 'b7d54d99bf11', 'Information Exchanged', '1430463600', '', 'routine', 'http://example.com', '') AS tmp
WHERE NOT EXISTS (SELECT url FROM table WHERE url = 'http://example.com')

我收到一条 SQL 错误,显示重复列名:'',因为某些记录没有传入评级注释

如何避免该错误?有没有更好的方法来实现这一目标?

最佳答案

您必须包含列的别名

INSERT INTO table (id, actions, date, comments, type, url, rating)
SELECT * FROM (SELECT 'b7d54d99bf11' as id,
'Information Exchanged' as actions,
'1430463600' as date,
'' as comments,
'routine' as type,
'http://example.com' as url,
'' as rating) AS tmp

关于mysql - 如果 MySQL 中的表中不存在则插入记录失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40433453/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com