有2个表 下面这个业务不知道是否能否用触发器来实现 
User (id, groupID)               (user的各个id都在各自的groupID组里 ,groupID允许为空)
limit(userId, limit)            (userID只能是存在的User的id,limit为整型 , userId 是该表的主键) 简单数据例子如下:
 User (id, groupID) 
        1     1
        2 
        3     1
        4     2  
        5     2 limit(userId, limit) 
        2       10
        3       50
        1       100        
        4       200
        5       200现在我思考能否用触发器来实现这个业务
当我修改 limit引发触发器比如当我修改 limit表的userId=3的 limit为1000的时候
触发器应该
1 select groupID from User where Id=3;
2 if groupID >0(这里groupID =1)  , then  select id from User where groupID =1;
   在触发器中把所有的 id 放到一个数组里, 
  之后 set n=数组长度    要设置的值new.limit/n  (这里为1000)
  之后再 update  limit set limit=new.limit/n   where userId in 数组 ;这里不知道这个触发器该如何写 (不知道是否能写)??   (mysql的触发器是否支持数组 以及复杂的循环 ??)

解决方案 »

  1.   

    1. MySQL 中不支持数组。
    2. "在触发器中把所有的 id 放到一个数组里" 可以用grouip_concat(id) 生成一个字符串序列 "1,3"
    3. update  limit set limit=new.limit/n   where find_in_set(id,'1,3') ; 语法上可以实现,但是! MYSQL在触发器中不能对本表进行update操作!
      

  2.   

    感谢楼上 google不能用了 ,死活找不到线索
    我准备用java代码来实现