select a.etId, a.name, 
group_concat(b.codeCont) as busiPro,
group_concat(c.codeCont) as busiPro2
from 
(select etId,Name,from etinfo where etId = 'et001') a,
(select codeCont from codetable where codeId in (select busiProId  from busiprolink where etId ='et001' order by busiProId)) b,
(select codeCont from codetable where codeId in (select settWayId from settwaylink where etId ='et001' order by settWayId)) c 
group by a.etId
结果:
etId:et001
name:武林外传
busiPro:火锅,火锅,火锅,烧烤,烧烤,烧烤,自助,自助,自助,海鲜,海鲜,海鲜
busiPro2:现金,信用卡,其他,现金,信用卡,其他,现金,信用卡,其他,现金,信用卡,其他
------------------------------------------------------------------
问题:
1 怎么busiPro和busiPro2才能不重复
2 当C没记录的时候,全部都没数据了,怎么才能当C没记录也不影响a和b的结果
  下面还会有很多表。比如d,e,f等等。。

解决方案 »

  1.   

    1、在c中把b里面加条件把b里面已经符合条件的codeCont去掉即可。
    2、用left join处理即可。
      

  2.   

    晕,没看清楚
    原来你的SQL是全连接啊?
    这样不行啊,搞些条件关联吧
      

  3.   

    select a.etId, a.name, 
    (select group_concat(codeCont) from codetable where codeId in (select busiProId  from busiprolink where etId ='et001' order by busiProId)) as busiPro,
    (select group_concat(codeCont) from codetable where codeId in (select settWayId from settwaylink where etId ='et001' order by settWayId)) as busiPro2
    from 
    (select etId,Name,from etinfo where etId = 'et001') a
      

  4.   

    感觉上你的SQL语句好象过于繁琐,类似功能不如直接在程序中实现。