现在有两张表,A表描述的是谈话人信息,B表描述的是谈话人的谈话记录
如果现在要把B表所有和A表中对应的人谈话的次数查询出来,更新到A表的talktimes字段,
显示每个人谈了多少次话,SQL语句该如何写呢?
表A:
---------------------------------------------------
A_ID   name   age   talktimes
1      张三   12 
2      李四   15
3      王五   14
.
.
.------------------------------------------表B:
------------------------------------------
B_ID  talktosb     name
1     jack         张三
2     Tom          王五
3     Bill         李四
4     Kim          张三  
5     dick         李四
.
.

解决方案 »

  1.   

    update a set talktimes=isnull(b.talktimes,0) 
    from (select name,count(*)  as talktimes from b group by name) b
    where a.name=b.name
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    update a set talktimes=count(*)
    from b
    where a.nane=b.name
    group by name
    _______________________________________________________________--
      

  3.   

    update a set talktimes=b.talktimes
    from (select name,count(*)  as talktimes from b group by name) b
    where a.name=b.name这样写是对的,我试过了.