私は次のような1つのテーブルmytradeを持っています
tradeid securityid quantity
111 899 12000
112 899 1000
113 788 15000
114 566 -15000
115 566 -1000
したがって、セキュリティIDの合計量を収集するには、次のクエリを記述します(これを#temptableに試し、temptableを作成してから、以下を選択します)。
select
tradeid,
securityid,
sum(quantity) OVER(Partition by securityid) as total
from mytrade
以下のような出力が得られます
tradeid securityid total
114 566 -16000
115 566 -16000
113 788 15000
111 899 13000
112 899 13000
ここで、「合計」数量に基づいて値をsecondtableに挿入します。
insert secondTable (securityid,quantity,price)
(
select securityid,quantity,101.1 from mydata..mytrade
where #temptable.total = 13000 and securityid = 899
)
しかし、エラーが発生します:
マルチパート識別子「#temptable.total」をバインドできませんでした。
このステートメント全体を#temptableに入れてから、上記のように割り当てると、このエラーも発生します。「合計」列をどのようにバインドする必要がありますか?