postgresql cumulative counts in date range
You should explain your logic in more detail.  If I implement what you seem to be asking for, it generates your desired result for 33, but not for 34.

If you don't count overlapping rows "below" you, then how can the first row of 33 have a count of 7?  And if you do count overlapping rows "below" you, then how can the first row of 34 have a count of 1?

select group_id, start_date, end_date, (
    select count(*) from foobar f2 where 
        f2.group_id=foobar.group_id and
        daterange(foobar.start_date,foobar.end_date) &amp;&amp; daterange(f2.start_date,f2.end_date)
    ) as active 
from foobar;


 group_id | start_date |  end_date  | active 
----------+------------+------------+--------
       33 | 2013-05-21 | 2014-05-19 |      7
       33 | 2013-05-21 | 2015-05-18 |      8
       33 | 2013-05-21 | 2016-05-23 |      9
       33 | 2013-05-21 | 2017-05-15 |     10
       33 | 2013-05-21 | 2099-12-31 |     12
       33 | 2013-05-21 | 2099-12-31 |     12
       33 | 2013-05-21 | 2099-12-31 |     12
       33 | 2014-05-20 | 2099-12-31 |     11
       33 | 2015-05-19 | 2099-12-31 |     10
       33 | 2016-05-24 | 2099-12-31 |      9
       33 | 2017-05-16 | 2099-12-31 |      8
       33 | 2019-01-24 | 2099-12-31 |      8
       34 | 2016-05-24 | 2099-12-31 |      4
       34 | 2017-05-16 | 2099-12-31 |      4
       34 | 2019-01-24 | 2099-12-31 |      4
       34 | 2019-05-31 | 2099-12-31 |      4