Form groups computing max - min depending on number of peers
If I understand correctly ...

Use a subquery and compute the value depending on the count of rows.
Then get the final result using the window function lag():

SELECT time_interval
     , CASE WHEN ct &gt; 1 THEN span ELSE span - lag(span) OVER (ORDER BY time_interval) END AS span
FROM  (
   SELECT date_trunc('minute', datetime) - ((EXTRACT(MINUTE FROM datetime)::int) % 15) * interval '1 minute' AS time_interval
        , CASE WHEN count(*) &gt; 1 THEN MAX(value) - MIN(value) ELSE MAX(value) END AS span
        , count(*) AS ct
   FROM   point
   WHERE  datetime BETWEEN '2011-01-01 07:00:00' and '2011-01-01 07:45:00'
   GROUP  BY 1
   ) sub