這兩個SQL語句給了我下面顯示的結果。我需要爲MerchantId
,BatchId
和Currency
在SQL Server中連接兩個表
分組來連接他們,我需要一個包含所有這些列
MerchantId - BatchId - T1 - T2- NotSold - Sold- Currency
查詢新表:
select
MerchantId as MerchantId,
BatchId as BatchId,
COUNT(BatchId)as T1, SUM(Amount) as NotSold,
Currency as Currency
from
[Order]
where
OrderStatus = 4 and MerchantId = 1
group by
BatchId, Currency,MerchantId
select
MerchantId as MerchantId,
BatchId as BatchId,
COUNT(BatchId) as T2,
SUM(Amount) as Sold,
Currency
from
[Order]
where
OrderStatus = 1 and MerchantId = 1
group by
BatchId, Currency,MerchantId
你的最終輸出是什麼樣的? – codingbiz