title: MySQL Avg Count With Where and Group By
body: <p>This table keeps records of calls that salespersons make :</p>
  
  <pre><code>id | clientid | salespersonid | call_duration | date | last_update
  1  | c2345    | sp34          | 05:00         | yyyy | yyyy
  2  | c2345    | sp34          | 05:00         | yyyy | yyyy
  3  | c2345    | sp35          | 05:00         | yyyy | yyyy
  4  | c2345    | sp36          | 05:00         | yyyy | yyyy
  5  | c2361    | sp36          | 05:00         | yyyy | yyyy
  6  | c2361    | sp36          | 05:00         | yyyy | yyyy
  </code></pre>
  
  <p>With this table I want to calculate two things :</p>
  
  <ol>
  <li><p>Average of calls per client : The average number of calls made per client.</p>
  
  <p>In this case number should return : 3</p></li>
  <li><p>Average of calls per salesperson : The average number of calls made per salesperson.</p>
  
  <p>In this case number should return : 2</p></li>
  </ol>
  
  <p>Calculating average is pretty much basic math stuff. It's just a matter of counting/adding and dividing by number of rows. But here in MySQL I cant figure out how I would do that without a specific value to provide for the WHERE CLAUSE? I mean if I wanted to calculate average for salesperson 34, I would specify <code>WHERE salespersonid=sp34</code>. And if I wanted to calculate average of call for client 2345 I would do <code>WHERE clientid=c2345</code> But here I'm wanting to calculate average of average.</p>