 <p>Again, <strong>without subquery</strong>:</p> <p>Key element is to add <a href="http://www.postgresql.org/docs/current/interactive/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS" rel="nofollow"><strong><code>PARTITION BY</code></strong></a> to the window function(s):</p> <pre><code>SELECT DISTINCT t.section -- ,sum(count(*)) OVER (PARTITION BY t.section) AS tickets_count ,sum(min(a.revenue)) OVER (PARTITION BY t.section) AS atendees_revenue FROM tickets t LEFT JOIN attendees a ON a.id = t.attendee_id GROUP BY t.attendee_id, t.section ORDER BY t.section; </code></pre> <p><a href="http://sqlfiddle.com/#!12/6e522/1" rel="nofollow"><strong>-> sqlfiddle</strong></a></p> <p>Here, you <code>GROUP BY t.attendee_id, t.section</code>, before you run the result through the window function. And use <code>PARTITION BY t.section</code> in the window function as you want results partitioned by section this time.</p> <p>Uncomment the second line if you want to get a count of tickets, too.</p> <p>Otherwise, it works similar to <a href="http://stackoverflow.com/a/13169627/939860">my answer to your previous question</a>. I.e., the rest of the explanation applies.</p>