title: selecting Top 5 max highs and 5 min Low for specific period say past 180 and 30 days in same query
body: <p>Following is the table data, need to find out the top 5 max high and min low for the entire 180 days and the same for the last 30 days in the same query.</p>
  
  <pre><code>Stock  High Low Date        prevclose ....
  ------------------------------------
  ABB    100   75  29/12/2019   90
  ABB     83   50  30/12/2019   87
  ABB     73   45  30/12/2019   87
  .
  .
  .
  .
  ABB    100    67  29/06/2019  90
  ABB     83    65  30/06/2019  81
  infy   100    75  29/12/2019  90
  infy    830  650  30/12/2019  810
  infy    730  645  30/12/2019  788 
  .
  .
  .
  infy   1001  556  29/06/2019  904
  infy    833  657  30/06/2019  812
  infy    734  643  30/06/2019  735
  </code></pre>
  
  <p>Query, which I tried, but getting an error at rank() cannot be used with window functions. any alternatives.</p>
  
  <pre><code>select * into SRTREND180 from (
  select *
  from (
      select 
          rank() over(partition by name order by high desc) rn_high180,
          rank() over(partition by name order by low asc) rn_low180,
          rank() over (partition by name order by high desc rows between 30 preceding and current row) rn_high30,
          rank() over (partition by name order by low asc rows between 30 preceding and current row) rn_low30,        
           t.*
      from Historic t
  ) Hist
  where rn_high180 &lt;= 5 or rn_low180 &lt;= 5 or  rn_high30 &lt;=5 or rn_low30 &lt;=5
  ) SR
  </code></pre>