title: PostgreSQL query to check minimum and maximum data
body: <p>i have the example database here,</p>
  
  <p>table products</p>
  
  <pre><code>id |  name  |  code  |  minimum_stock  |  stock  |  maximum_stock  
  1     AAA      AAA            50           75           100
  2     BBB      BBB            70           50           300
  3     CCC      CCC            100          200          150
  4     DDD      DDD            40           25           100
  5     EEE      EEE            70           10           100
  </code></pre>
  
  <p>in this case i want to show only data who is stock exceed compared by their minimum_stock or maximum_stock(below or above their minimum maximum stock) and also i want to show datain safe stock position (between minimum and maximum stock),
  stock value in here is a result from aggregate sum function</p>
  
  <p>if i want only show data exceed minimum stock, the result output must be like this</p>
  
  <pre><code>id |  name  |  code  |  **minimum_stock**  |  **stock**  |  maximum_stock  
  2     BBB      BBB            **70**           **50**           300
  4     DDD      DDD            **40**           **25**           100
  5     EEE      EEE            **70**           **10**           100
  </code></pre>
  
  <p>and if i want only show data exceed maximum stock, the result output must be like this</p>
  
  <pre><code>id |  name  |  code  |  minimum_stock  |  **stock**  |  **maximum_stock**  
  3     CCC      CCC            100          **200**          **150**
  </code></pre>
  
  <p>and the last one the stock between minimum and maximum stock, it must be like this</p>
  
  <pre><code>id |  name  |  code  |  **minimum_stock**  |  **stock**  |  **maximum_stock**  
  1     AAA      AAA            **50**           **75**           **100**
  </code></pre>
  
  <p>how can I do that?</p>