表结构
    name,code,sex;
    xxx , 1000, m
    yyy , 1001, w
    zzz , 1002, m我要查询,如果xxx的sex 等于 zzz的sex就返回真,否则返回假,SQL server有没有这样功能?

解决方案 »

  1.   

    if (select count(distinct sex) from tb where code=1000 or code=1002 )=1
    print '真'
    else 
    print 'false'
      

  2.   

    if exists(select 1 from tb m ,tb n where m.name = 'xxx' and n.name = 'zzz' and m.sex = n.sex )
       print 'true'
    else
       print 'false'
      

  3.   

    select case A.sex = B.sex the 1 else 0 end
    from tb A,tb B
    whre A.name='xxx' and B.name='zzz'
      

  4.   

    if exists(select 1 from tb a ,tb b where a.name = 'xxx' and b.name = 'zzz' and a.sex = b.sex)
    pritn '一样'