Grouping date's as 1 count if difference is 5 days
If I understand your question, the following is the query that you are looking for.

SQL&gt; select * from mytest;

        ID DT
---------- ---------
        22 15-MAY-17
        22 15-MAY-17
        22 15-MAY-17
        22 16-MAY-17
        22 22-MAY-17
        23 23-MAY-17
        23 25-MAY-17
        23 30-MAY-17

8 rows selected.

SQL&gt; select id, count(diff)+1 count 
     from( 
          select id, dt - lag(dt) over(order by dt) diff 
          from mytest
          ) 
     where diff &gt;= 5 
     group by id;

        ID         COUNT
---------- -------------
        22             2
        23             2


Here is the fiddle.

For more about LAG()

Documentation: LAG