导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

寻找一条SQL语句!

dizhuzai 2008-01-14 01:14:39
表A有字段ArticleID,ArticlePlCount,其中ArticleID是主键
表B有字段ID,ArticleID,Conntext
现在想从表B中统计每个ArticleID的记录数来更新表A的ArticlePlCount的字段。表A的ArticleID和表B的ArticleID是关联的。
...全文
74 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
utpcb 2008-01-14
update A

set ArticlePlCount=(select count(*) from B where A.ArticleID=B.ArticleID)
from A
回复
honghuali 2008-01-14
UPDATE A SET ArticlePlCount = aa.ArticleCount
FROM A,
(SELECT ArticleID, COUNT(*) AS ArticleCount FROM B GROUP BY ArticleID)aa
WHERE aa.ArticleID = A.ArticleID[/code]
回复
liangyuan198412 2008-01-14
update A SET ArticlePlCount= SL
FROM A ,(SELECT ArticleID,COUNT(*) AS SL FROM b GROUP BY ArticleID)
WHERE A.ArticleID=B.ArticleID
回复
kk19840210 2008-01-14

update a set ArticlePlCount=b.ArticlePlCount from a inner join (select ArticleID,ArticlePlCount=count(1) from b group by ArticleID) b on a.ArticleID=b.ArticleID
回复
wyb0026 2008-01-14

update A set ArticlePlCount=sum
from A inner join
(select ArticleID,count(*) sum
from b
group by ArticleID ) as T
on A.ArticleID=T.ArticleID

回复
leo_lesley 2008-01-14
update t
set t.ArticlePlCount=a.cnt
from 表A t inner join (select ArticleID,cnt=count(ArticleID) from 表B group by ArticleID) a on t.ArticleID=a.ArticleID
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告