and if you need all 12 months for all countries regardless of whether data is available or not, you need to have calendar table like belowhttp://visakhm.blogspot.com/2010/02/generating-calendar-table.htmland use likeSELECT m.country,m.Period,COALESCE(n.MonthlySales,0) AS MonthlySalesFROM(SELECT country,[Period]FROM (SELECT DISTINCT country FROM table)tCROSS JOIN (SELECT DATENAME(mm,m.[Date]) + ' ' + DATENAME(yyyy,m.[Date]) AS [Period] FROM dbo.CalendarTable (@yourstartdate,@yourenddate,0,1)f)u )mLEFT JOIN (SELECT s.Country, SUM(s.SalesAmount) as MonthlySales,d.YearMonthFROM SalesHistory sINNER JOIN Dates d ON s.SalesDate = d.DateIDGROUP BY s.Country, d.YearMonth)nON n.country = m.countryAND n.[YearMonth] = m.[period]
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/