Okay, if you're confirming that you want to exclude some date ranges, then I'll ignore the statement "The new ranges does cover 30th sept" (because they doesn't) and I take into account that you want to filter out data, not just to group them.
What exactly do you need from us? Just the grouping? Or do you need something about the range calculation logic as well?
I don't know where you have the logic calculating ranges, but in general, I don't think you simply do it in a select statement. I see two ways:
- Run one select for each group; summarize values and filter by from date and to date. Put the result to a temporary table.
- Create a view with a computed column which will identify the range where each of the records belong (if it's possible). Then you can group by this computed column.