有一个文章分类表class, 其中有一个该分类下文章总数的字段 ArticleTotal。另外有一个文章表 Article。 其中有一个classId 字段代表属于某个文章分类。如何计算每个文章分类下的 文章总数,然后赋给文章分类表 articleTotal字段 该怎么写?update class set articleTotal=(select count(*) from article where classId=???) 帮忙看看
update class set articleTotal=(select count(*) from article where classId=class.classId)
--MS是水源的于娜,:)update A set ArticleTotal=isnull([count],0) from class A,(select classId,count(*) as [count] from Article group by classID) B where A.classID=B.classID
的確是名人 :) 加個判斷update class set articleTotal=IsNull((select count(*) from article where classId=class.classId), 0)
set ArticleTotal=isnull([count],0)
from class A,(select classId,count(*) as [count] from Article group by classID) B
where A.classID=B.classID
加個判斷update class set articleTotal=IsNull((select count(*) from article where classId=class.classId), 0)