Quote:
I have done my code using photo mysql but I take more than 7 hours in execution please guide me for reduce time
You wonder the reason why your code takes so much time to execute?
The reason is very simple: cascading
- you do 1 query with up 8000 records
- for each record you loop 200 time
- and then you have 4 query
- and then a single insert
Total select = 8000 * 200 * 4 =
6,400,000 selects
Total insert = 8000 * 200 =
1,600,000 inserts
You need to really learn how SQL works and how to optimize queries.
Rather than the 200*4 queries in the for loop, I would do a single query of raw data outside of the for loop, and then building the sums inside the for loop.