GROUP BY with subqueries for a Group?
Use a CASE statement to check if RecordNumber = 0 | 2147483647.

Try this version:

select   Content-&gt;&gt;'Group' as "Group", 
         min(case when Content-&gt;&gt;'RecordNumber' = '0' 
                  then Content-&gt;&gt;'When' 
                  else null 
             end ) "Start",
         max(case when Content-&gt;&gt;'RecordNumber' = '2147483647' 
                  then Content-&gt;&gt;'When' 
                  else null 
             end ) "Stop",
         count(*) as "Count"
from     DocumentStore
group by Content-&gt;&gt;'Group'
order by Content-&gt;&gt;'Group'
;


The result:

| Group | Start      | Stop       | Count |
|-------|------------|------------|-------|
| 0     | 1490280300 | 1490280500 | 3     |
| 1     | 1490280600 | 1490280700 | 2     |
| 2     | 1490280900 | NULL       | 2     |


As Evan Carroll pointed out, you can also take advantage of the FILTER clause. Have a look at 4.2.7 Aggregate expressions in the Postgres docs.

select   Content-&gt;&gt;'Group' as "Group", 
         min(Content-&gt;&gt;'When') filter (where Content-&gt;&gt;'RecordNumber' = '0') "Start",
         max(Content-&gt;&gt;'When') filter (where Content-&gt;&gt;'RecordNumber' = '2147483647') "Stop",
         count(*)  as "Count"
from     DocumentStore
group by Content-&gt;&gt;'Group'
order by Content-&gt;&gt;'Group'
;


Check it here: http://rextester.com/ADYG46620