gpt4 book ai didi

syntax-error - INSERT sql 语句中的嵌套 SELECT

转载 作者:行者123 更新时间:2023-12-04 01:42:36 31 4
gpt4 key购买 nike

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

4年前关闭。




Improve this question




有人能告诉我为什么这不起作用吗?

INSERT INTO Medical_History (pid, grafts, allergies,  diseases, surgearies, treatment)
VALUES ((SELECT pid FROM Pet WHERE pet_name='Jack' AND cid=(SELECT cid FROM Customer WHERE last_name='Iwannidis' AND first_name='Giwrgos')),
'grafts', 'allergies', 'diseases', 'surgearies', treatments');

我收到一个语法错误:
unrecognized token "');"

最佳答案

select嵌套在 values语句看起来错误(我不确定所有数据库都接受它)。一种更典型的表达方式是:

INSERT INTO Medical_History (pid, grafts, allergies,  diseases, surgearies, treatment)
SELECT pid, 'grafts', 'allergies', 'diseases', 'surgearies', 'treatments'
FROM Pet
WHERE pet_name='Jack' AND
cid=(SELECT cid
FROM Customer
WHERE last_name='Iwannidis' AND first_name='Giwrgos'
);

如果子查询返回多个值,这一点尤其重要。那么查询很可能会出错。

关于syntax-error - INSERT sql 语句中的嵌套 SELECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16782597/

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