解决方案 »
- mysql源码安装时遇到的问题,请高手赐教!
- InnoDB: Error: trying to declare trx to enter InnoDB, but
- win2003 mysql服务能正常启动,工具连不上提示10055,重启服务器正常
- 帮忙看一下下面的这些状态结果,请帮我判断一下,谢谢
- 关于mysql的问题,有phpmyadmin管理中,出现了一些奇怪的进程
- 我的在本地用mysql control center管理MYSQL数据库,然后我想把这些表,和数据导入到网上的数据库该怎么弄呀!`
- mysql怎样与vc链接?
- 怎样确认数据库引擎?
- 建表的时候遇到的问题!!
- 有关mysql得小问题
- 把.csv文件导入mysql是产生错误
- 吐槽一下Mysql !!! 差点让他搞崩溃
参考一下这个贴子的提问方式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)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
where 20032 not in (attention_user_id, user_id);
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;
如图:
+---------+-----------+
| 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>