0
我有一個查詢:追加顏色值查詢結果
declare @colors table (color varchar(50));
declare @T table(RowNo int, LocationID bigint, TotalSales money, DBAName varchar(50), Color varchar(50));
insert into @colors
select distinct Color
from dbx.dbo.SampleData;
select top 5 *
from @colors
order by newid()
insert into @T
select (row_number() over (order by LocationID)) as RowNo,
LocationID, sum(TransAmount) as TotalSales, DBAName, Color
from dbx.dbo.SampleData
group by LocationID, DBAName, Color
select * from (
select LocationID, TotalSales, DBAName
from @T
) x
group by LocationID, TotalSales, DBAName
它擁有以下結果:
我想知道如何RIGHT JOIN
(或任何其他更好的解決方案)@colors
轉換爲@T
,以便每行具有如下獨特的顏色值:
我很感激任何幫助。謝謝!
行應該有什麼顏色?我們如何爲每一行選擇正確的顏色? – Lamak
顏色在查詢中拉出。檢查圖片。我創建了兩個表格。一個有顏色值,另一個有數據。 –
是的,我現在可以檢查它,你編輯你的問題與新圖片,包括該信息 – Lamak