Skip to content
Advertisement

Getting ratios in mysql without subqueries

I would like to run a query from the tables below that gives me the ratio of the amount paid from the executive offices to the total amount due:

The expected result is as below :

I have been able to get totalpaid from exec offices as below

and the totalsdue as below

What I have tried without success:

How to get the expected results with a single query.

Advertisement

Answer

For the result you could use the subquery in JOIN

for better performance ..
check if you really need like and wildchar matching or you can result ve the query with exact matching

and be sure you have proper index on columns potenzially involved in join and where

table cheques column ( officeID, payee)

or if the column status allow exact match column ( officeID, status, payee)

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