这两个 SQL 语句给了我如下所示的结果。我需要通过分组来连接它们MerchantId
,BatchId
并且Currency
我需要一个包含所有这些列的新表
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