title: SQL latest record per group with an aggregated column
body: <p>I have a table similar to this:  </p>
  
  <pre><code>STOCK_ID TRADE_TIME   PRICE     VOLUME  
  123         1           5         100  
  123         2           6         150  
  456         1           7         200  
  456         2           8         250
  </code></pre>
  
  <p>For each stock I want to get latest price (where latest is just the max trade_time) and aggregated volume, so for the above table I want to see:  </p>
  
  <pre><code>123  6 250  
  456  8 450 
  </code></pre>
  
  <p>I've just discovered that the current query doesn't (always) work, ie there's no guarantee that the price selected is always the latest:  </p>
  
  <pre><code>select stock_id, price, sum(volume) group by stock_id
  </code></pre>
  
  <p>Is this possible to do without subqueries? Thanks!</p>