本帖最后由 XiangZhiLiu 于 2013-05-11 16:14:05 编辑

解决方案 »

  1.   

    假设userInfo表中有20032,20033,20034,20035,20036,20055的数据。
      

  2.   

    假设userInfo表中有20032,20033,20034,20035,20036,20055的数据。
      

  3.   

       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
      

  4.   

    列出来建表语句和insert语句 你这愿意给你回答
      

  5.   

    select * from t
    where 20032 not in (attention_user_id, user_id);
      

  6.   


    CREATE TABLE user_Infos
    (
    user_id   INT,
    user_name VARCHAR(20)
    );
    INSERT INTO user_Infos VALUES(20032,'a');
    INSERT INTO user_Infos VALUES(20033,'b');
    INSERT INTO user_Infos VALUES(20034,'c');
    INSERT INTO user_Infos VALUES(20035,'d');
    INSERT INTO user_Infos VALUES(20036,'e');
    INSERT INTO user_Infos VALUES(20055,'f');
    CREATE TABLE attentionUser 
    (
      id INT,
      attention_user_id INT,
      user_id INT
    );
    INSERT INTO attentionUser VALUES(1,20033,20032);
    INSERT INTO attentionUser VALUES(2,20034,20032);
    INSERT INTO attentionUser VALUES(3,20035,20032);
    INSERT INTO attentionUser VALUES(4,20032,20033);
    INSERT INTO attentionUser VALUES(5,20035,20034);
    INSERT INTO attentionUser VALUES(6,20032,20035);
    SELECT * FROM user_Infos;
    SELECT * FROM attentionUser;
    如图:
      

  7.   

    mysql> SELECT * FROM user_Infos;
    +---------+-----------+
    | user_id | user_name |
    +---------+-----------+
    |   20032 | a         |
    |   20033 | b         |
    |   20034 | c         |
    |   20035 | d         |
    |   20036 | e         |
    |   20055 | f         |
    +---------+-----------+
    6 rows in set (0.00 sec)mysql> SELECT * FROM attentionUser;
    +------+-------------------+---------+
    | id   | attention_user_id | user_id |
    +------+-------------------+---------+
    |    1 |             20033 |   20032 |
    |    2 |             20034 |   20032 |
    |    3 |             20035 |   20032 |
    |    4 |             20032 |   20033 |
    |    5 |             20035 |   20034 |
    |    6 |             20032 |   20035 |
    +------+-------------------+---------+
    6 rows in set (0.00 sec)mysql> select a.user_id,b.user_id
        -> from user_Infos a,user_Infos b
        -> where a.user_id!=b.user_id
        -> and not exists (
        ->  select 1 from attentionUser
        ->  where user_id=a.user_id and attention_user_id=b.user_id
        ->  )
        -> order by 1,2;
    +---------+---------+
    | user_id | user_id |
    +---------+---------+
    |   20032 |   20036 |
    |   20032 |   20055 |
    |   20033 |   20034 |
    |   20033 |   20035 |
    |   20033 |   20036 |
    |   20033 |   20055 |
    |   20034 |   20032 |
    |   20034 |   20033 |
    |   20034 |   20036 |
    |   20034 |   20055 |
    |   20035 |   20033 |
    |   20035 |   20034 |
    |   20035 |   20036 |
    |   20035 |   20055 |
    |   20036 |   20032 |
    |   20036 |   20033 |
    |   20036 |   20034 |
    |   20036 |   20035 |
    |   20036 |   20055 |
    |   20055 |   20032 |
    |   20055 |   20033 |
    |   20055 |   20034 |
    |   20055 |   20035 |
    |   20055 |   20036 |
    +---------+---------+
    24 rows in set (0.00 sec)mysql>
      

  8.   

    感谢版主ACMAIN_CHM ,恍然大悟啊!!!