这两个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