title: Store common query as column?
body: <p>Using PostgreSQL, I have a number of queries that look like this:</p>
  
  <pre><code>SELECT &lt;col 1&gt;, &lt;col 2&gt;
       , (SELECT sum(&lt;col x&gt;)
          FROM   &lt;otherTable&gt; 
          WHERE  &lt;other table foreignkeyCol&gt;=&lt;this table keycol&gt;) AS &lt;col 3&gt;
  FROM   &lt;tbl&gt;
  </code></pre>
  
  <p>Given that the sub-select will be identical in every case, is there a way to store that sub-select as a pseudo-column in the table? Essentially, I want to be able to select a column from table A that is a sum of a specific column from table B where the records are related. Is this possible?</p>