update table1 set colcount=(select count(时间分类)/2 from table2 where 员工编号=20021218001 and 时间分类=1.1)
  where 记录编号=2112203只是稍微有一点简化

解决方案 »

  1.   

    按table1中的时间分类、记录编号进行count,然后将结果插入table2对应的时间分类列中
      

  2.   

    table1:
    员工编号
    记录编号
    时间分类table2:
    记录编号
    员工编号
    分类1
    分类2
    ……你说的联系是指什么?
      

  3.   

    update table1 
    set 分类1=a.分类1,分类2=a.分类2,...分类X=a.分类X
    from table1 b,(
    select 员工编号,sum(case when 时间分类='分类1' then 1 else 0 end) as 分类1,sum(case when 时间分类='分类2' then 1 else 0 end) as 分类2,
    ...
    sum(case when 时间分类='分类X' then 1 else 0 end) as 分类X
    from table2 group by 员工编号
    ) as a
    where a.员工编号=b.员工编号
    注意:你的table1、table2搞反了。
    对两个表的员工编号加索引。
      

  4.   


    select 员工编号,sum(case when 时间分类='分类1' then 1 else 0 end) as 分类1,sum(case when 时间分类='分类2' then 1 else 0 end) as 分类2,
    ...
    sum(case when 时间分类='分类X' then 1 else 0 end) as 分类X
    from table2 group by 员工编号
    看是不是你需要的数据再update
      

  5.   

    非常感谢CCEO!结贴。
    以后请多多指教!