orders資料表:
order_id order_date order_price order_qty dept_id
A0001 2017-05-12 100 20 D1
A0002 2017-06-22 200 30 D1
A0003 2018-01-13 750 12 D1
A0004 2018-03-22 450 17 D1
A0005 2017-07-13 400 10 D2
A0006 2017-09-24 300 20 D2
A0007 2018-05-15 250 32 D2
A0008 2018-06-26 150 47 D2
A0009 2017-02-21 200 40 D3
A0010 2017-04-20 100 50 D3
A0011 2018-06-17 350 32 D3
A0012 2018-08-26 450 27 D3
ss_order資料表:
Year dept_id Amt
2017 D1
2017 D2
2017 D3
2018 D1
2018 D2
2018 D3
營業額為order_price*order_qty
問題:
如何取得各部門年度總營業額更新到ss_order的Amt欄位
select year( order_date) Year, dept_id ,sum(order_price*order_qty) Amt
INTO ss_order
from orders
group by year( order_date),dept_id