- 积分
- 244
- UID
- 11322
- 阅读权限
- 20
- 注册时间
- 2012-4-19
- 精华
- 在线时间
- 小时
- 最后登录
- 1970-1-1
- 职业
- 1
|
本帖最后由 business124 于 2012-6-18 10:41 编辑
- <P> BEGIN
-
- declare Pmax int; -- 记录表中最大ID
- declare Pmin int; -- 记录表中最小ID
- declare PID smallint(6);-- 记录当前统计Pack_ID,用于与总表userservicerelation联系,统计Pack_ID的人气
-
- delete from packcollectionrank;-- 清空表
- insert into packcollectionrank(Pack_ID) select distinct Pack_ID from products ;-- 插入所有Pack_ID到统计表packcollectionrank</P>
- <P> select MAX(ID) into Pmax from packcollectionrank;
- select MIN(ID) into Pmin from packcollectionrank;</P>
- <P> while Pmin<=Pmax do-- 插入所有Pack_ID的人气,没订阅默认为0
- select Pack_ID into PID from tdxtb_packcollectionrank where ID=Pmin;</P>
- <P> set @sql1=CONCAT("UPDATE packcollectionrank SET Collection_count=(SELECT COUNT(*) FROM userservicerelation WHERE Pack_ID=",PID," AND Relation_Status=6) WHERE Pack_ID=",PID,";");
- PREPARE rankpack1 FROM @sql1;
- EXECUTE rankpack1; </P>
- <P> set Pmin=Pmin+1;
- end while;
- -- 插入
- END
- </P>
复制代码 本机执行:时间: 0.250ms
Procedure executed successfully
受影响的行: 1
换机子执行:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare Pmax int;
MYSQL后版本都是5.5.17
这怎么解释,求高人指点!!
|
|