1
我試圖找出最簡潔的方式來實現以下結果集:
給該輸入數據:
覆蓋數據
注意行1和3個輸入數據由相同的項目+桶組合組成。與「任務」的源行應該優先於行以「預測」,用於生成結果集時匹配項+桶組合的來源。在項目+桶組合具有不重複由於差的來源的情況下,這些行是出現在不論其來源的設置的最終結果。
下面是輸入數據的代碼:
declare @t table
(
source varchar(20) not null,
item int not null,
bucket date not null,
quantity int not null,
primary key clustered (source, item, bucket)
);
insert into @t values
('forecast', 8501, '9/1/2016', 100),
('forecast', 8528, '9/1/2016', 100),
('mandate', 8501, '9/1/2016', 200),
('mandate', 8530, '9/1/2016', 200);
select * from @t;
現在,簡潔! – knot22