0
従業員一人当たりのコスト表があります。表は、特定の従業員に対して複数の行を持ち、各行に別々のコストを持つことができます。私は各従業員のための総コストを持っている一時テーブルで終わりたいです。したがって:異なる名前と値の合計を持つ一時テーブルを作成します
Name | Cost
Dave | 563.22
John | 264.00
私は以下を試しましたが、コストを更新するのに無効です。何が間違っていますか?そしてこれを行うより良い方法があります。
declare @temp2 table
(
name text,
cost integer
)
insert @temp2(name) SELECT DISTINCT ename6 from dbo.condensed7day_query_result
UPDATE t
SET t.cost = sum(dbo.condensed7day_query_result.cost)
FROM dbo.condensed7day_query_result
WHERE dbo.condensed7day_query_result.ename6 = t.name)
FROM @temp2 t
select * from @temp2