表:Contact两个字段:   A        B
   hu      美团    hu添加了美团为好友(单向)
   hu      拉手    hu添加了拉手为好友(单向)
   美团     hu     美团添加了hu为好友............请问各位L怎样查询hu的双向好友...3Q3Q3Q

解决方案 »

  1.   

     A                 B
      hu              美团         hu添加了美团为好友(单向)
      hu              拉手         hu添加了拉手为好友(单向)
      美团            hu           美团添加了hu为好友
      

  2.   

    select *  from Contact where A='hu' or B='hu'
      

  3.   

    lZ试下这个select * from (select * from Contact where A='hu' ) as A1 ,(select * from Contact where B='hu' ) as A2 where A1.B = A2.A
      

  4.   

    Select thename,count(*) as scount From 
    {
    select b as thename from Contact where A='hu'
    UNION
    select a as thename form Contact where b='hu'
    } as newTable Group by thename scount >=2为双向,否则为单向
      

  5.   

    对头 大概就是这个思路。where 后面再加一个条件 把美团加上
    select b as thename from Contact where A='hu' and B='美团'
    UNION
    select a as thename form Contact where b='hu' and A='美团'
    搜索2个的Count 加起来=2就可以了