I have a database with one table of complaints and the date they were sent. I have to do this, given the start and end dates of the two periods, I have to calculate the percentage of growth between them.
For instance:
To calculate height:
The information I must extract from this report, which claims grew 100% between Q1 and Q2
Here is what I came up with:
SELECT (SELECT COUNT(id) FROM complaints WHERE submit_date >= start_date_period_1 AND submit_date <= end_date_period_1) AS q1_claims, (SELECT COUNT(id) FROM complaints WHERE submit_date >= start_date_period_2 AND submit_date <= end_date_period_2) AS q2_claims, (SELECT ((q2_claims - q1_claims)/q2_claims * 100) AS 'Percentage Growth') FROM complaints;
but does not show the result in the correct form. It shows an entry for each date for a given period. How can I fix the request?
source share