Requirements: the list of data with a stored procedure (different time take a different form, such as in the first half of 2017 is tableName2017A, the second half of the year it is tableName2017B), and then insert another table,
If not variable, is writing the following:
Create procedure findAverageTime ()
The begin
Declare hasNext int the default 1;
Declare row_insertTime timestamp;
Declare row_username varchar (50);
Declare row_averageTime int (6);
Declare cursorName cursor for
The select insertTime
The username,
Avg (waitTime) "averageTime
"The from
Tb_order2017B
Where
Status='1'
And
Finished='2'
And
WaitTime!
='0'And
Date_format (inserttime, 'Y - m - % d % %)=date_format ((select date_sub (now (), the interval 1 day),' Y - m - % d % % ')
Group by
The username;
Declare the exit handler for the NOT FOUND set hasNext:=0;
The open cursorName;
Repeat
The fetch cursorName into row_insertTime, row_username row_averageTime;
Insert into averageTime values (row_insertTime row_username, row_averageTime);
Repeat until hasNext=0 end;
The close cursorName;
End $
Now according to the time you need to establish the data table, namely above tb_order2017B need to write,