update table1 set num1=(select count(*) from table2 where workid=table1.workid)

解决方案 »

  1.   

    1:
    update table1 set num1=(select count(*) from table2 where workid=table1.workid)2:
    update a set a.num1 = b.num
    from table1 a
    join (Select workid,count(*) as num from table2 group by workid) b 
       on a.workid = b.workid
      

  2.   

    update语句,上面高手已经说过了。我做过人事考勤软件,烦死了,哪会这么简单呀。比如,事假,往往不是一整天,而是以小时计的。所以,你的表1应该是记录事假起止时间,而不应该是一个一个的日期。尤其是请长假时,你的表结构就更显出问题了。表1是多余的。做成视图就行了。