璩雷的博客

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

mysql 临时表联合修改统计数据

文章表:blog_article
文章分类表:blog_category
现在统计出文章分类下的文章数然后修改文章分类表的文章数字段的值:
思路:建一临时表得出统计数据,然后用联合更新

create  table  tmptable

SELECT category_id,count(1) as count1 from blog_article group by category_id;
update  blog_category  bc inner join tmptable  bb on bc.id = bb.category_id  set bc.article_num =bb.count1 ;
drop table tmptable;
posted on 2008-09-04 15:22  璩雷  阅读(567)  评论(0)    收藏  举报