有表和字段
sysgtemgroup :系统目录表
1.sysGroupId :系统目录ID,例 1
2.supplierCount:供应商数据统计 例 1000 
company : 公司表
1.companyId:公司ID
2.sysGroupId:公司所在的系统ID 例 0,2,333,2314,0
(因为一个公司可能会是三种行业的,所以可以填三个目录号)我试写了几个更新,比如产品更新(sql就不列出来了)现在卡在公司更新上了,以下是我写的语句update systemgroup a
set supplierCount = (select count(companyId) as count from company t where a. sysGroupId like t.sysGroupId )那么问题出在,条件上
a.sysGroupId like t.sysGroupId
这样写,字符短的 like 字符长的,明显不可以
如果反过来的话
t.sysGroupId like  a.sysGroupId
必须在a.sysGroupId,的前后加上','
(因为我like 2的话,连同2314这个目录也会算进在内)
那有什么办法可以解决吗?速度慢点也没关系,一个月一次的,就是不能死机
第二个也心烦
update systemgroup a set productCount = (select sum(productCount)  as count from systemgroup  where parentid=a. sysGroupId) where depth=2 and child>0
mysql4.1不让在更新中,查找更新表,怎么办怎么办

解决方案 »

  1.   

    不知道你的数据库上是否可以使用存储程序。
    如果不行的话,也可以用shell或者其他可以在服务器上运行的脚本语言来更新数据。
      

  2.   

    关于第一个问题,
    主要的毛病出在你保存数据库的方式上。如果按照你这种保存方式,只能写成这样,而且还要保证逗号间没有空格:
      t.sysGroupId like '%,a.sysGroupId,%' 
      

  3.   

    我觉得,第一个问题,有可能无解
    比如sysGroupId 为:
    2,22,222
    你怎么做到找出任意的一个?%Id 只能找到最后一个
    %Id, 什么都找不到
    %,Id, 什么都找不到
    %,Id,%只能找到22如果几种情况用or,可能会重了
    ---------------
    我也期待高手来解决这个问题
      

  4.   

    升级5.1,否则建立视图
    select parentid,sum(productCount)  as count   from   systemgroup group by parentidupdate systemgroup a,视图 b set a.productCount=b.count  where   depth=2   and   child> 0
      

  5.   


    sysGroupId   :系统目录ID,例   1 
    是这种形式,就可以
    update   systemgroup   a
    set   supplierCount   =   (select   count(companyId)   as   count   from   company   t   where  concat(',',a.sysGroupId,',') like concat(',', t.sysGroupId,','))如是2,22,222 这种形式,必须拆分字符串