我正在尝试将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;
答案 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;