I have a group of BigQuery tables which collect test results on a day by day basis, each table being named like various_tests.test_name_20190523. I have a query which I can run over specified date ranges to find the number of failures and ratio of failures to all tests, but I'd prefer to get a table with several date ranges each as a row in the table, e.g. BETWEEN "20190901" AND "20190916", BETWEEN "20190916" AND "20191001", BETWEEN "20191001" AND "20191016". The columns of each row will be the same as the single-row result here. What's a good way to do this?
SELECT
"20190916" as StartDate, "20191001" as EndDate,
SUM(CASE WHEN status IN ("BAD") AND foo = 'bar' then 1 else 0 end) as Bad, COUNT(*) as Total,
(SUM(CASE WHEN status IN ("BAD") AND foo = 'bar' then 1 else 0 end)/ COUNT(*)) as Ratio
FROM
`various_tests.test_name_*`
WHERE
_TABLE_SUFFIX BETWEEN "20190916" AND "20191001"
(The real query has several more conditions in the WHERE and CASE clauses but they are elided for clarity.)