sql_base: select a.name,(select name from E e where e.id=1), c.name from A
                left join D d on d.a_id=a.id
                left join E e on e.id = a.e_id
                left join C c on c.a_id=a.id
             where 1=1
                     and a.id=1 and a.g_id=1 and e.id=1
         先在需求是: E 和 C  的值传过来多个,
                                E1    C1
                                E2    C2
                                …    …
                      结果想  name   e1   c1
                              name   e1   c2
                              name   e1   c3  …
                               name  e2   c1
                              name   e2   c2
                              name   e3   c1
                              name   e3   c2
                                       ……
              e.id=1 要和 下面的 e 值同步 

解决方案 »

  1.   

    sql_base: select a.name,e.name, c.name from A
       left join D d on d.a_id=a.id
       left join E e on e.id = a.e_id
       left join C c on c.a_id=a.id
       where 1=1
       and a.id=1 and a.g_id=1 and e.id in(你的多个E值)
      

  2.   

    详细说明要求
    贴建表及插入记录的SQL,及要求结果出来看看
      

  3.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  4.   

    select a.name,e.name, c.name from A
      left join D d on d.a_id=a.id
      left join E e on e.id = a.e_id
      left join C c on c.a_id=a.id
      where 1=1
      and a.id=1 and a.g_id=1 and e.id=1
      

  5.   

    :from A 的时候少了个小a别名…这样 是可以的,之前也想到了,种种的实验结果的问题不仅仅是sql的问题了,整个表,和表之间的关系有问题……
    e的值总是显示第一个……(该死的项目也不知我是第几个接的了,哎!)