【问题标题】:Column name or number of supplied values does not match table definition.?列名或提供的值的数量与表定义不匹配。?
【发布时间】:2021-11-06 23:40:40
【问题描述】:
Drop table if exists #populationpercentagevaccine
Create Table #populationpercentagevaccine
(
Continent nvarchar(255),
location nvarchar(255),
Date Datetime,
Population numeric,
New_vaccinations numeric,
cumulative_vaccine numeric
)

我的表执行得很完美,但是代码 INSERT INTO 给我带来了问题

Insert into #populationpercentagevaccine
  select death.Continent, death.location, death.Date, death.Population, vaccine.New_vaccinations, 
    sum(convert(int,vaccine.new_vaccinations )) over(partition by death.location order by death.location, death.date) as cumulative_all_vaccine 

我创建了表并插入到同一个表中导致列名或提供的值的数量与表定义不匹配该问题

【问题讨论】:

  • 您的插入语句中缺少 cumulative_vaccine。我刚刚添加了该列。 @AshishYadav。表中的列数与插入语句不匹配。而且您的查询也没有 from 子句和 join s
  • 我试过了,但没用,我有完整的连接子句查询
  • 如果您可以添加我可以检查的完整查询。添加了示例答案。我用了你给的桌子
  • 您刚刚编辑了问题。
  • 我实际上仍然看到旧查询

标签: sql sql-server tsql sql-server-2008 sql-insert


【解决方案1】:

您的表格列和插入中提供的列之前不匹配。

   Insert into #populationpercentagevaccine
    select Continent, [location], [Date], [Population], New_vaccinations
    , sum(convert(int,new_vaccinations )) over(partition by [location] order by [location, [date]) as cumulative_all_vaccine 
    from #populationpercentagevaccine 

这是你之前的问题:

 Create Table #populationpercentagevaccine
  (
   Continent nvarchar(255),
   location nvarchar(255),
   Date Datetime,
   Population numeric,
   New_vaccinations numeric,
   cumulative_vaccine numeric,
   cumulative_all_vaccine numeric
   )

 Insert into #populationpercentagevaccine
  select Continent, [location], [Date], [Population], New_vaccinations, cumulative_vaccine --this was missing earlier
  , sum(convert(int,new_vaccinations )) over(partition by [location] 
       order by [location, [date]) as cumulative_all_vaccine 
    from #populationpercentagevaccine

【讨论】:

    【解决方案2】:

    您的表有 7 列,您的查询仅提供其中 6 列的值。 提供值或插入标识

    【讨论】:

      猜你喜欢
      • 2018-12-24
      • 2010-11-12
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 2018-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多