【问题标题】:SQL Help | The select list for the INSERT statement contains fewer items than the insert listSQL 帮助 | INSERT 语句的选择列表包含的项目少于插入列表
【发布时间】:2017-06-01 15:23:43
【问题描述】:

请在下面查看我的查询,

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 ' ;

在这我想要一个静态的订单号,其余的应该来自​​一个表(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.

任何解决方案。

【问题讨论】:

  • 您确定您使用的是 MySQL 吗? dbo 通常是 SQL-Server。
  • VALUES() 中的列数需要与要插入的表中的列数相匹配。

标签: mysql


【解决方案1】:

您不能同时拥有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 ' ;

【讨论】:

    【解决方案2】:

    我的问题已经解决,下面是对我有用的查询

    插入到 Exam_Trigger(问题、CAT_ID、TOPIC_ID、SCHEDULED_TYPE、UPDATE_USER、UPDATE_DT、CREATE_USER、CREATE_DT) select id ,'2','2','Weekly','',curdate(),'',curdate() from ( select GROUP_CONCAT(id SEPARATOR ',')as id from(select id from question_data order by rand () 限制 4)as ls) as ps

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多