CREATE DEFINER=`dbuser`@`%` PROCEDURE `proc_statics_Phone_object_all`()
begin
DECLARE phoneid VARCHAR(60);
DECLARE object_Cursor CURSOR FOR SELECT `phoneid` FROM phone_object;
OPEN object_Cursor;
myLoop : LOOP
-- 循环游标中的数据,并赋值到变量中
FETCH object_Cursor INTO phoneid;
/**统计单个对象的短信、通话记录、QQ聊天、微信聊天数**/
UPDATE phone_object
SET
smsnum = (SELECT count( 1 ) smsnum FROM phone_sms WHERE phoneid = phoneid),
callnum=( SELECT count( 1 ) callnum FROM phone_call WHERE phoneid = phoneid ),
qqnum =( SELECT count( 1 ) qqnum FROM phone_im_account_msg WHERE phoneid = phoneid AND im_account_type = '11001' ),
wxnum =( SELECT count( 1 ) wxnum FROM phone_im_account_msg WHERE phoneid = phoneid AND im_account_type = '11002' )
where
phoneid = in_phoneid;
commit;
END LOOP myLoop;
CLOSE object_Cursor;
end