I have a table called projects that have the following link:
There are many contributions to this In my result set, I need the following total values:
- Number of unique contributors (donation on contribution table)
- Total contribution (SUM
- Total payment made (SUM of payment amount on the amount of payment)
Because many jobs and many more Join, it gets messy, I also have the ability to sort and filter these areas by the standard total work group, so I have come up with two options:
using the subkey Do:
As a project .ID in the form of project, (payment of payment by payment amount) ProjectID = PROJECT_ID) as a total payback, (select from contribution (separate Donor) WHERE recipients from contributions D = PROJECT_ID) as a contributor calculation, (select sum (amount) contributions from the recipient WHERE id = PROJECT_ID) from the total project;
Using a temporary table:
If the project_type exists, then drop table; Temporary table project_im (create project Iid INT, total_payment INT, total_dress INT, total_elected INT, primary key (project_id)) engine = create memory; Include in Project_Temp (project_id, total_payments) Select `project`.Id, IFNULL (SUM (PaymentAmount), 0) exclude project 'Include in Group on ProjectID =` project'; 1 by ID1 group; Select 'Project_ID', Project_IDOrs, Receive Total_Replace `Project '.ID, IFNULL (COUNT) (Direct Donorida), 0), Afal (Amount (zodiac), 0) to exclude` Project' on 'Contributions' Recipient ID = Project Duplicate key update on ID Group 1 Total_does = value (total_sual), total_funded = value (total_free); Choose * from Project_Temp;
Comparison of tests for both is comparable, with 1,000 rows in 0.7 - 0.8 seconds. But I'm really worried about scalability, and I do not have to re-engineer all tables. What is the best way?
Good for knowing time for every 1K rows, but the real question is they used Will go
Are you planning to send all of these back to the UI? Google outcomes 25 results per page; Maybe you should also
Are you planning to calculate in the middle level? You may be able to do those calculations on the database and take them all bytes into the wire.
My point is that you do not have to work with 1,000 or million lines if you think what you think
what is the difference between two questions You can give details of the plan to see.
Comments
Post a Comment