sql while语句及procedure

CREATE PROCEDURE myProc()
BEGIN
    DECLARE num INT DEFAULT 0;
    DECLARE stime TIMESTAMP;
    DECLARE etime TIMESTAMP;
    DECLARE cnt INT DEFAULT 0;
    WHILE num<90 DO
        SET stime="2018-07-01 00:00:00" + INTERVAL num DAY;
        SET etime="2018-07-01 23:59:59" + INTERVAL num DAY;
--      SELECT count(*) INTO cnt FROM usertpiactivity where time>=stime and time<=etime;
--      INSERT INTO temp SET period=num,utpicount=cnt;
--      SELECT count(*) INTO cnt FROM usertpisactivity where time>=stime and time<=etime;
--      UPDATE temp SET utpiscount=cnt where period=num;
        UPDATE temp SET day=stime where period=num;
        SET num=num+1;
    END WHILE;
END

你可能感兴趣的:(sql while语句及procedure)