LISTING 4: Solution 1, Last Step: Ranges of Months with Similar Trends SELECT MIN(smonth) AS from_month, MAX(smonth) AS to_month, CASE trend WHEN 1 THEN 'Up' WHEN -1 THEN 'Down' WHEN 0 THEN 'Same' ELSE 'Unknown' END AS trend FROM VTrendsDiff GROUP BY diff, trend ORDER BY from_month