In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `temp_data` ADD INDEX `temp_data_idx_script_code_rownum` (`script_code`,`rownum`);
SELECT
t1.*,
(SELECT
avg(t2.last_price)
FROM
temp_data t2
WHERE
t2.rownum > t1.rownum - 50
AND t2.rownum <= t1.rownum
AND t1.script_code = t2.script_code) AS 'ma_small_price'
FROM
temp_data t1