I want to calculate a percentage for the number of successful applications grouped by State.
I'm using mySQL and I can run a query to obtain a list of states with the number of total applications and successful applications. I am not sure how to combine the two queries and then try and calculate a percentage value. I'm assuming I have to run a subquery of some kind here, but not too sure.
SELECT w.state, c.case_status, COUNT(w.state) AS No_Applications
FROM worksites w JOIN cases c USING (WorksiteID)
WHERE c.Case_Status like '%certified%'
GROUP BY w.state
ORDER BY w.state ASC;
SELECT w.state, COUNT(w.state) AS No_Total_Applications
FROM worksites w JOIN cases c USING (WorksiteID)
GROUP BY w.state
ORDER BY w.state ASC;
SELECT w.state, c.case_status, COUNT(w.state FROM worksites w JOIN cases c WHERE c.Case_Status like '%certified%') AS Success_Applications,
COUNT (w.state) AS Total_Applications
FROM worksites w JOIN cases c USING (WorksiteID)
GROUP BY w.state
ORDER BY No_Applications ASC;
The first two codes return the number of successful and total applications respectively; the third code was my attempt and merging the two -- it failed saying "Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM worksites w JOIN cases c WHERE c.Case_Status like '%certified%') AS Success' at line 1"