title: How can easy select into temp table in MySQL?
body: <p>I need to create a temp table in one procedure.<br>
  Now my steps were:<br>
  1. DROP TEMPORARY TABLE if EXISTS<br>
  2. CREATE TEMPORARY TABLE<br>
  3. Do something with the table<br>
  4. DROP TEMPORARY TABLE if EXISTS</p>
  
  <p>I do not want to create the temp table every time when I call the procedure.<br>
  I just want to truncate the temp table,but how to select some data into the existing temp table??</p>
  
  <p>How to make the blow procedure run faster?</p>
  
  <pre><code>DROP PROCEDURE IF EXISTS `test`;
  DELIMITER ;;
  CREATE PROCEDURE `test`(IN type INT)
  begin
  
  DECLARE done INT DEFAULT 0; 
  DECLARE total INT DEFAULT 0;
  DECLARE min_1 INT DEFAULT 0;
  DECLARE min_10 INT DEFAULT 0;
  DECLARE min_30 INT DEFAULT 0;
  DECLARE tmp INT DEFAULT 0;
  DECLARE cursor1 CURSOR FOR SELECT TIMESTAMPDIFF(MINUTE,time1,time2) as dif FROM t_test ;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  
  DROP TEMPORARY TABLE if EXISTS t_test;
  CREATE TEMPORARY TABLE t_test AS (
    SELECT optime as time1,dtime as time2
    FROM tbmytest
    WHERE thetpye = type);
  
  OPEN cursor1;
  REPEAT
  FETCH cursor1 INTO tmp;
  IF done = 1 THEN
    close cursor1;
  ELSE
    SET total = total + 1;
    IF tmp &gt; 30 THEN
      SET min_30 = min_30 + 1;
    ELSEIF tmp &gt; 10 THEN
      SET min_10 = min_10 + 1;
    ELSEIF tmp &gt; -1 THEN
      SET min_1 = min_1 + 1;
    END IF;
  END IF;
  UNTIL done END REPEAT;
  
  DROP TEMPORARY TABLE if EXISTS t_test;
  SELECT min_1,min_10,min_30,total;
  end;;
  DELIMITER ;
  </code></pre>