これら 2 つの 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