--使用like来解决select sum(total) from A a
where exists(select 1 from B
             where id=1 and alist like concat('%',a.id,'%'));

解决方案 »

  1.   

    那样似乎效果并不是太好,我已经解决了
    其实很简单,replace(alist,",","','")替换一下就好了
      

  2.   

    --使用like来解决select sum(total) from A a
    where exists(select 1 from B
    where id=1 and alist like concat('%',a.id,'%'));
    ---------------------------------
    不是太明白
    为什么会是alist like?alist应该是根据B的ID唯一提出来的呀
      

  3.   

    用IN的话除非ID和你select出来的某一条结果相等才会是 true,
    你现在的ID只是某一个结果的一部分,所以用like.
      

  4.   

    恩,问题已经解决
    用exists在mysql中有时候会出现提不出的问题
    最后我这样处理的:
    select sum(A.total) from A,B
    where B.id=1 and B.alist like concat('%',a.id,'%'));