title: sql - oracle - selecting the first and last record for specific group/sku
body: <p>I've been trying to come up for answer but no success.</p>
  
  <p><strong>Need to get:</strong> price for the first purchase and price for the last purchase and grouped by SKU.</p>
  
  <p>Query results should be like this:</p>
  
  <pre><code>sku      first_purchase_price      Last_purchase_price   
  BC123    3.09                      6.68    
  QERT1    9.09                      13.23
  </code></pre>
  
  <p><strong>My Query</strong></p>
  
  <pre><code>SELECT sku,PRICE,MAX(purchase_DATE),MIN (purchase_DATE)
  FROM store
  ORDER By sku
  </code></pre>
  
  <p><strong>keep getting:</strong></p>
  
  <pre><code>SQL Error: ORA-00979: not a GROUP BY expression
  00979. 00000 -  "not a GROUP BY expression"
  </code></pre>
  
  <p><em>or</em></p>
  
  <pre><code>SQL Error: ORA-00937: not a single-group group function
  00937. 00000 -  "not a single-group group function"
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>
  
  <pre><code>SKU     TRANSAC_ID  purchase_DATE      PRICE
  ----------------------------------------------
  BC123   CHI0018089  21-OCT-09          6.98
  BC123   CHI0031199  11-MAR-13          6.68 
  BC123   NAP1000890  22-JAN-08          3.09 
  BC123   NAP1011123  21-DEC-11          89.9 
  QQQ789  NAP1000891  22-JAN-08          4.01 
  QERT1   JOL0400090  8-MAR-12           13.23 
  QERT1   NAP1000990  22-FEB-08          9.09 
  QERT1   NAP1001890  28-FEB-09          2.09 
  WW000   CHI0031208  11-MAR-13          200.01 
  WW000   CHI0031298  11-MAR-13          200.01 
  YZV11   JOL0200080  10-OCT-06          230.23 
  YZV11   AUR0700979  14-APR-13          6.68 
  YZV11   CHI0018189  03-OCT-09          556.98 
  YZV11   JOL0300080  10-MAR-11          300   
  </code></pre>