Reputation: 1
I have a table with the following columns
StoreId,Date,Total,Type
There are two queries which are working as expected but I want to make one query which will do both the tasks. Please help
select lRetailStoreId,szDate,sum(dTaTotal) as GiftCardSales
from TxSaleLineItem
where szTypeCode='GIFT'
group by lRetailStoreID,szDate
select lRetailStoreId,szDate,sum(dTaTotal) as TotalSalesByDay
from TxSaleLineItem
group by lRetailStoreID,szDate
Upvotes: 0
Views: 32
Reputation: 147146
You can use conditional aggregation:
select lRetailStoreId,
szDate,
sum(case when szTypeCode='GIFT' then dTaTotal else 0 end) as GiftCardSales,
sum(dTaTotal) as TotalSalesByDay
from TxSaleLineItem
group by lRetailStoreID, szDate
Upvotes: 1