We have a MySQL database that we are using to measure automated test successes and failures. Now we need to query the database to find out how many failures happened per day and what the cause was. The queries I've come up with so far go something like this:
select * from failures
where time >= '{time}' and time <= '{time} 23:59:59' and cause = '{fail_type} failed'
I have a couple of variations of this query. The problem I am running into is that we need to query the database for this information for 1, 7 and 56 days. This means I run the query 1 time, 7 times and 56 times, respectively. As the number goes up, the length of time for the query gets really long. I also have to run each of these queries for each failure type, which really adds to the query time.
Is there a more efficient way to query the database? So far, the closest question I've found on Stack was this one:
Note: I am running this query in a Flask-based web app and then graphing the results.