title: How to reduce time to process data in procedure of mysql
body: <p>Thank you forum...please help me..
  I have table which contain TagName and other table contains taglog  .im passing tag names to procedure called GetAvg which will return avg of all tags.it works well, but it takes about 35 sec to show 100 tag values.how to reduce time .please help me im new in database.</p>
  
  <pre><code>DELIMITER $$
  CREATE DEFINER=`root`@`localhost` PROCEDURE `GetAvg`(IN FromTime datetime, IN ToTime   datetime)
  BEGIN
  DECLARE  no_more_alarms INT DEFAULT 0;
  DECLARE  TempTagName VARCHAR(45);
  DECLARE  val FLOAT;
  DECLARE  cur_tag CURSOR FOR
        select Tag_AVG from Report
        where(Tag_AVG IS NOT NULL );
        DECLARE  CONTINUE HANDLER FOR NOT FOUND
        SET  no_more_alarms = 1;
  
  
  DROP TABLE IF EXISTS `tempAVG`;
  
  CREATE  TABLE tempAVG (
  val FLOAT
  );
  
  
  OPEN  cur_tag;
  
  FETCH  cur_tag INTO TempTagName;
  REPEAT
  
  SELECT AVG(value) INTO val
  FROM jas_taglog
  WHERE ((TagId = (select TagId from jas_tags where jas_tags.Name = TempTagName)) AND jas_taglog.LogTime between FromTime and ToTime) ;
  
  INSERT  INTO tempAvg(Val)
  VALUES  (val);
  
  FETCH cur_tag INTO TempTagName;
  UNTIL  no_more_alarms = 1
  END REPEAT;
  CLOSE  cur_tag;
  SELECT *  FROM tempAVG;
  
  END
  </code></pre>