错误 - INSERT具有比目标列更多的表达式

时间:2016-01-23 19:49:21

标签: sql sql-server

我正在尝试将number_of订单插入storiacloud.schl_storia_school_status_try。计算在另一个表(storiacloud.vw_storia_oms_orders)中完成。问题在于它正在尝试插入school_ucn,但我只是将其用于group by并且不想插入它。有人可以帮忙吗

INSERT INTO storiacloud.schl_storia_school_status_try
(no_of_orders)
select school_ucn,count(otc_order_number)
from storiacloud.vw_storia_oms_orders
group by school_ucn;

2 个答案:

答案 0 :(得分:2)

您可以从选择中删除它:

INSERT INTO storiacloud.schl_storia_school_status_try (no_of_orders) 
select count(otc_order_number) 
from storiacloud.vw_storia_oms_orders
group by school_ucn;

它仍会分组,只是不报告。我不确定在表中使用一堆随机数是多少。

答案 1 :(得分:0)

...或在INSERT的列列表中添加缺少的列:

INSERT INTO storiacloud.schl_storia_school_status_try
   (no_of_orders,   [YOUR_NB_ORDER_COLUMN]    )
select school_ucn,count(otc_order_number)
from storiacloud.vw_storia_oms_orders
group by school_ucn;