Skip to content
Advertisement

PHP and Mysql, avoid multiple loop queries

I have a table myTable that looks like this:

for a given date range, I need to show count of rows per date, per agent, and count(rows)-count(qualif = Q1) / count(rows)

To explain more, the way I do it on my PHP page is query first for:

And when looping through the result for each agent and date, I query for:

The expected result for a period between ‘2019-05-11’ AND ‘2019-05-12’

taking into consideration if tot=0;

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?

Advertisement

Answer

You could use conditional SUM(), as in:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement