I am trying to count offer redemptions for every day over the last 30 days. I want to return a zero if there are no redeemed offers on that particular date for that offer type.
SELECT
a.offertype,
CONVERT(date,b.[date]) ,
COUNT( a.offertype )
FROM [dbo].[Last30days] b
LEFT JOIN [dbo].[Offers] a ON CONVERT(date,b.[date]) = CONVERT(date,a.[RedeemedDate])
LEFT JOIN [dbo].[UniqueOffers] c ON a.offertype = c.OfferType
WHERE CONVERT(date,[RedeemedDate]) >= CONVERT(date,GETDATE()-30)
GROUP BY
a.offertype,
CONVERT(date,b.[date])
ORDER BY
a.offertype,
CONVERT(date,b.[date])
Last30day table > has a date for each day for the last 30 days
UniqueOffers table > has every distinct offer in the offers table
offers > has the offer type and the date of redemption