title: Oracle SQL query for Group By with Having clause
body: <p>I have Table A below:</p>
  
  <pre><code>HashKey     QueueStatus     CreationDateTime
  1             IMM           21-NOV-18 01.56.28.977628000 AM
  1             DEF           21-NOV-18 01.58.28.971628000 AM
  1             SENT          21-NOV-18 01.59.28.977628000 AM
  2             IMM           21-NOV-18 02.56.28.977628000 AM
  2             MAN           21-NOV-18 02.57.28.977628000 AM
  2             SENT          21-NOV-18 02.58.28.977628000 AM
  </code></pre>
  
  <p>I have another table B below:</p>
  
  <pre><code>HashKey     ReleaseStatus  TrxNo  
  1             SENT          XYZ
  2             SENT          XYZ
  3             null           XYZ
  </code></pre>
  
  <p>Now I need a query which gives me The all columns from B table which have the ReleaseStatus as SENT and previous Queue status(CreationDateTime is the factor to decide) from Table A.</p>
  
  <p>In this example I need the result as -</p>
  
  <pre><code>HashKey     ReleaseStatus  TrxNo   QueueStatus as PrevoiusQueueStatus
    1           SENT           XYZ       DEF
    2           SENT           XYZ       MAN
  </code></pre>
  
  <p>I have tried with having &amp; group by queries on Table A but not able to getting the previous one by Having clause.    </p>
  
  <p>Some of trial (select Hashkey,count(creationdatetime) from QueuedRecords group by Hashkey having creationdatetime