一个表字段为:T1,
另一个表的字段和第一个表字段一样: T1;
现在想检索生成出一个表,是T1,B1;
如果第一个表的T1值在第二个表中T1有出现,就返回B1为真,反之为假.
这个查询出生的表怎么实现?

解决方案 »

  1.   

    select 
    a.T1,
    b1=case exists(select * from tb2 where a.t1=t1 ) then  1 else 0 end
    from tb1 a 
      

  2.   

    消息 156,级别 15,状态 1,第 3 行
    关键字 'exists' 附近有语法错误。
    消息 156,级别 15,状态 1,第 3 行
    关键字 'then' 附近有语法错误。
      

  3.   

    select 
    a.T1,
    b1=case when exists(select * from tb2 where a.t1=t1 ) then  1 else 0 end
    from tb1 a 
      

  4.   

    select 
    a.T1,
    b1=case when exists(select * from tb2 where a.t1=t1 ) then  1 else 0 end
    from tb1 a 
      

  5.   

    select distinct 
    a.T1, 
    b1=case when exists(select * from tb2 where a.t1=t1 ) then  1 else 0 end 
    from tb1 a 
      

  6.   

    如果表中不包含 T1 值为 NULL 的记录:select
        A.T1,B1=(case when B.T1 is null then '假' else '真' end)
    from
        A
    left join
        B
    on
        A.T1=B.T1
      

  7.   

    select 
     distinct a.T1, 
     case when exists(select * from tb2 where a.t1=t1 ) then  '真' else '假' end as b1
    from
     tb1 a 
      

  8.   

    select t1,b1= case when exists (select 1 from 表2 where 表1.t1=表2.t1)  
    then '真' else '假' end
                   from 表1  
      

  9.   

    select 
    a.T1,
    case when exists(select * from 表B where a.t1=t1 ) then  '真' else '假' end as B1
    from 表A a 
      

  10.   


    你好,能不能请教一个问题,就是你回复的这个sql code框框是怎么弄进来的,我不知道怎么弄,是不是很白痴,不过确实不懂...
    请教中....
      

  11.   


    回复内容第一排 找到插入源代码 选择里面的SQL