title: Mysql Calculate percentage with group by clause?
body: <p>I have a requirement to calculate the percentage of customers within first quarter BY customers within first quarter and status is 'Available'. I am doing something like this which is not giving correct results.</p>
  
  <pre><code>SELECT DISTINCT Customer, COUNT(1) / (select count(1) from table where QUARTER(`Creation_Date`) = 1) 
  FROM table
  WHERE Customer is not null and QUARTER(`Creation_Date`)=1 and `Status` = 'Available' 
  GROUP BY Customer
  </code></pre>
  
  <p>I want to add group by 'Customer' in first inner select i.e. something like below but that obviously returns more than one rows.</p>
  
  <p><code>select count(1) / select count(1) from table where QUARTER(</code>Creation_Date<code>) = 1 
   and Customer = 'ABC'</code></p>
  
  <p>Currently its calculating like e.g. 4/225*100.</p>
  
  <p>Need percentage like this using groupby:</p>
  
  <p>for each customer:</p>
  
  <pre><code>X = select count(1) from table where QUARTER(`Creation_Date`) = 1 and Customer = 'X' and Status = 'Available';
  Y = select count(1) from table where QUARTER(`Creation_Date`) = 1 and Customer = 'X';
  Z = X/Y*100
  </code></pre>
  
  <p>Can someone please guide?</p>