title: SUM/COUNT of CASE within CASE in MYSQL
body: <p>Have below Column in table product : </p>
  
  <pre><code>a  |  b  | cat
  --------------
  2  |  4  |  1
  3  |  1  |  1
  4  |  4  |  1
  2  |  1  |  1
  3  |  2  |  1
  5  |  3  |  1
  8  |  7  |  2
  5  |  3  |  2
  
  
  $sql = "SELECT 
          SUM(CASE 
              WHEN
              cat = 1
              AND
              a &gt; b  
              THEN 1 else 0 end) as prdplus
          FROM product
         ";
  </code></pre>
  
  <blockquote>
    <p>in above query i am getting value for <em>sum or count</em>  of <strong>a</strong> greater
    then <strong>b</strong></p>
  </blockquote>
  
  <p>which is  3>1 , 2>1 , 3>2 , 5>3 </p>
  
  <p>hence output of above query will be : <strong><em>4</em></strong></p>
  
  <pre><code>prdplus
  -------
  4
  </code></pre>
  
  <blockquote>
    <p><strong><em>what i need</em></strong> is <strong>count value have only +1</strong> <em>in above count</em> of <strong>4</strong></p>
  </blockquote>
  
  <p>thats with above query now i need +1 value count</p>
  
  <pre><code>3-1 = 2
  2-1 = 1  // just explanation purpose , output i need in -&gt; plus1 
  3-2 = 1  // just explanation purpose , output i need in  -&gt; plus1
  5-3 = 2
  </code></pre>
  
  <p>hence with above query  i need only +1 count which is <strong>2</strong></p>
  
  <p>i am not getting how to write case within case including above query as i need both count to show in my table as below</p>
  
  <p><strong><em>Output Final :</em></strong> </p>
  
  <pre><code> prdplus | plus1 
  ----------------
    4      |  2
  </code></pre>