I am having table that contains 20000 data. and i have to create new table that calculates some records about analysis.In new table i have to create 25 coloumns. from which i have created query and script that calculates all records according to my condition. but last three coloumns takes lots of time. i already optimized queries that calculates other 23 coloumns. now the query for last three coloumns is as below : (1) for annual not renewals
select count(*)
from payment
where (find_in_set('Standard',product)
OR find_in_set('Lite',product)
OR find_in_set('Basic',product)
OR find_in_set('Nifty50',product)
OR find_in_set('NiftyOnly',product)
)
AND '" + subscriptionDate + "' NOT BETWEEN subscr_date AND end_date
AND payment_type ='annual'
HAVING (MIN(subscr_date) < '" + subscriptionDate + "');
(2) for quarter not renewals:
select count(*)
from payment
where (find_in_set('Standard',product)
OR find_in_set('Lite',product)
OR find_in_set('Basic',product)
OR find_in_set('Nifty50',product)
OR find_in_set('NiftyOnly',product)
)
AND '" + subscriptionDate + "' NOT BETWEEN subscr_date AND end_date
AND (payment_type ='quarter'
OR payment_type='Quarterly'
)
HAVING (MIN(subscr_date) < '" + subscriptionDate + "');
(3) for month not renewed :
select count(*)
from payment
where (find_in_set('Standard',product)
OR find_in_set('Lite',product)
OR find_in_set('Basic',product)
OR find_in_set('Nifty50',product)
OR find_in_set('NiftyOnly',product)
)
AND '" + subscriptionDate + "' NOT BETWEEN subscr_date AND end_date
AND payment_type ='month'
HAVING (MIN(subscr_date) < '" + subscriptionDate + "');
I am using find_in_set() for checking only products .this 3 queries will run under while loop and that loop will be iterated for 20000 data. now how can i reduce execution time for this queries?