a,b字段是表1的数据结构       c 是表2的数据结构
a        b          c
-----------------  -----
1 非GMP 2, 10
2 GMP 2, 10
10 单独定价 2, 10
0 其它 2, 10
以下SQL语句得出上面的数据
select tab1.a,tab1.c,tab2.c from tab1,tab2 where 
instr(tab2.c,tab1.a) > 0
and tab2.id = 100 
求:如何写SQL语句得出以下数据列表
b                c
-----------------------    
GMP,单独定价    2,10

解决方案 »

  1.   

    select tab1.c,tab11.c,tab2.c from 
    (select tab1.c from tab1,tab2 where 
    instr(tab2.c,tab1.a) > 0 and tab2.id = 10)tab1
    (select tab1.c from tab1,tab2 where 
    instr(tab2.c,tab1.a) > 0 and tab2.id = 2)tab11
      

  2.   

    楼下的 tab2.id = 10 这样是不是已经定死了,表2 c字段的值是动态,上面只是举个例子
      

  3.   

    waikey(人生一笑而过)  tab2.id 这样写是何意义
      

  4.   

    楼上的应该不行。
    我觉得这里的2和10是不固定的,是由tab2.id = 100 查出来的。
    要把tab2.c按','截串,然后找到和tab1.a对应的tab1.b,再用','拼起来,这样用一条sql不好写吧学习