These two SQL statements give me the results shown below. I need to concatenate them by grouping for MerchantId, BatchId and Currency
I need a new table that contains all these columns
MerchantId - BatchId - T1 - T2- NotSold - Sold- Currency
Queries:
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
You will want to use the aggregate function with a
CASEexpression:See SQL Fiddle with Demo
Using your sample data the result is: