gpt4 book ai didi

mysql - SQL 帮助 | INSERT 语句的选择列表包含的项目少于插入列表

转载 作者:行者123 更新时间:2023-11-29 06:01:55 24 4
gpt4 key购买 nike

请看下面我的查询,

insert into dbo.orderDetails(orderNo,clientId,productId,quantity)
values(' ee941422-5546-4d62-b5d6-60ecd13ca2b8 ')
select client_id,product_id,amount from dbo.cart
where client_id =' efc08f7c-fdfc-4712-9488-fc1c55acb95e ' ;

在此我想要一个静态 orderno,其余的应该来自​​表(dbo.cart)。当我执行我的查询时它显示这个错误

There are more columns in the INSERT statement than values specified in the 
VALUES clause. The number of values in the VALUES clause must match the
number of columns specified in the INSERT statement.

任何解决方案。

最佳答案

您不能同时拥有 VALUESSELECT。如果要插入静态值,请将其放入 SELECT 列表中。

insert into dbo.orderDetails(orderNo,clientId,productId,quantity)
select ' ee941422-5546-4d62-b5d6-60ecd13ca2b8 ', client_id,product_id,amount from dbo.cart
where client_id =' efc08f7c-fdfc-4712-9488-fc1c55acb95e ' ;

关于mysql - SQL 帮助 | INSERT 语句的选择列表包含的项目少于插入列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44311566/

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