title: PHP and Mysql, avoid multiple loop queries
body: <p>I have a table myTable that looks like this:</p>
  
  <pre><code>+-------+-------+--------+------------+
  | Id    | Agent | Qualif |    Date    |
  +-------+-------+--------+------------+
  |     1 | A     | Q1     | 2019-05-11 |
  |     2 | B     | Q2     | 2019-05-11 |
  |     3 | C     | Q1     | 2019-05-12 |
  |     4 | A     | Q1     | 2019-05-11 |
  |     5 | A     | Q2     | 2019-05-11 |
  +-------+-------+--------+------------+
  </code></pre>
  
  <p>for a given date range, I need to show count of rows per date, per agent, and count(rows)-count(qualif = Q1) / count(rows)</p>
  
  <p>To explain more, the way I do it on my PHP page is query first for:</p>
  
  <pre><code>SELECT date, Agent, count(*) as tot
       FROM myTable
       WHERE date between d1 and d2
       group by date, agent
  </code></pre>
  
  <p>And when looping through the result for each agent and date, I query for:</p>
  
  <pre><code>SELECT count(*) as totQ1 FROM my table WHERE date='somedate' and agent='someagent' and qualif='Q1'
  </code></pre>
  
  <p>The expected result for a period between '2019-05-11' AND '2019-05-12'</p>
  
  <pre><code>+------------+--------+-----+-----------+
  |   date     | Agent  | tot | division  |
  +------------+--------+-----+-----------+
  | 2019-05-11 | A      |   3 | 2/3       |
  | 2019-05-11 | B      |   1 | 1         |
  | 2019-05-12 | C      |   1 | 1         |
  +------------+--------+-----+-----------+
  </code></pre>
  
  <p>taking into consideration if tot=0;</p>
  
  <p>Is there any way I can combine all of this into one query so I don't have to query multiple times for each date and agent?</p>