求一句SQL(去除表中只出现过一次行) 表内容如: id name 1 AAA 2 AAA 3 BBB 4 CCC 5 BBB希望取出 id name 1 AAA 2 AAA 3 BBB 5 BBB就是希望不要取出仅仅现过一次的CCC这一行。谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from a join (select name from a group by name having count(*) > 1) as b on a.name = b.name mysql> create table t1 -> ( -> id int not null auto_increment primary key, -> name char(3) -> );Query OK, 0 rows affected (0.08 sec)mysql> insert into t1 (name) values -> ('AAA'),('AAA'),('BBB'),('CCC'),('BBB');Query OK, 5 rows affected (0.06 sec)Records: 5 Duplicates: 0 Warnings: 0mysql> select * from t1;+----+------+| id | name |+----+------+| 1 | AAA || 2 | AAA || 3 | BBB || 4 | CCC || 5 | BBB |+----+------+5 rows in set (0.02 sec)mysql> select * from t1 group by name having count(name) >1;+----+------+| id | name |+----+------+| 1 | AAA || 3 | BBB |+----+------+2 rows in set (0.00 sec) select * from a where id in (select id from a group by name having count(*) > 1) select * from tt where t not in (select t from tt group by t2 having count(*) = 1) 根据ip查询各个城市的注册人数 怎样写一个通用的表结构复制的语句呢? 请问各位天处理库存并发访问时如何处理 mysql很慢不知道为什么?才1.5w的数据就跑了3分钟,而且我加了索引啊~有图麻烦大家帮忙看看啊~ 请教mysql 的问题 table 表名 is full 是啥错误 怎样修改mysql的库结构? 帮忙解释一下“过程”这个概念吧~! 提升mysql更新速度的问题 MySQL安装了无法打开 大神 求解 mysql56总是出现1067错误 请教一个mysql的分组查询问题? perl(Class::MethodMaker) is needed by 怎么处理
-> (
-> id int not null auto_increment primary key,
-> name char(3)
-> );
Query OK, 0 rows affected (0.08 sec)mysql> insert into t1 (name) values
-> ('AAA'),('AAA'),('BBB'),('CCC'),('BBB');
Query OK, 5 rows affected (0.06 sec)
Records: 5 Duplicates: 0 Warnings: 0mysql> select * from t1;
+----+------+
| id | name |
+----+------+
| 1 | AAA |
| 2 | AAA |
| 3 | BBB |
| 4 | CCC |
| 5 | BBB |
+----+------+
5 rows in set (0.02 sec)mysql> select * from t1 group by name having count(name) >1;
+----+------+
| id | name |
+----+------+
| 1 | AAA |
| 3 | BBB |
+----+------+
2 rows in set (0.00 sec)