compare dates in results
As said by @ypercube, lag() will help.

select id,
       (d - lag) as lag, 
       case when (d - lag) &lt; interval '24 hours' then false else true end as p
from (
      select id, 
             (datetime) as d, 
             lag(datetime) over (order by id) as lag 
      from lagtest
     ) as t;


For the first row no lag will be displayed.