如表所示,刚才的一个问题叙述有问题,现重新发一个
a  b二个表 
当 b 表中的信息同时a表也存在时,c输出为1 否则输出为 0a       b
001     0
00101   001
00102   001
0010101 00101
0010201 00102
...a       b      c
001     0      0
00101   001    1
00102   001    1
0010101 00101  0
0010201 00102  0
...

解决方案 »

  1.   

    select b.*,case when a.id is not null then 1 else 0 end as c
    from b
    left join a on b.id=a.id
      

  2.   

    select tb.a,tb.b,(case when b.a is null then 0 else 1 end) c
    from tb left join ta
    on ta.a=tb.a and ta.b=tb.b
      

  3.   


    用的知识点 left join  case when .... then ...else ...end
    楼上都正解
      

  4.   

    不好意思。我又写错了
    是一个表
    a b二个字段
     
    当 b 字段中的信息同时a字段也存在时,c输出为1 否则输出为 0a       b
    001     0
    00101   001
    00102   001
    0010101 00101
    0010201 00102
    ...a       b     c
    001 0   0
    00101   001   1
    00102   001   1
    0010101 00101 0
    0010201 00102 0
    ...