仅显示在MySQL中出现至少三次的重复列名
COUNT()为此使用HAVING。让我们首先创建一个表-
mysql> create table DemoTable1351
-> (
-> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> StudentName varchar(40)
-> );使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1351(StudentName) values('Chris');
mysql> insert into DemoTable1351(StudentName) values('Bob');
mysql> insert into DemoTable1351(StudentName) values('Bob');
mysql> insert into DemoTable1351(StudentName) values('David');
mysql> insert into DemoTable1351(StudentName) values('Bob');
mysql> insert into DemoTable1351(StudentName) values('David');
mysql> insert into DemoTable1351(StudentName) values('Bob');
mysql> insert into DemoTable1351(StudentName) values('Mike');
mysql> insert into DemoTable1351(StudentName) values('David');使用select语句显示表中的所有记录-
mysql> select * from DemoTable1351;
这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Bob | | 3 | Bob | | 4 | David | | 5 | Bob | | 6 | David | | 7 | Bob | | 8 | Mike | | 9 | David | +-----------+-------------+ 9 rows in set (0.00 sec)
这是显示至少出现三次的重复列名的查询-
mysql> select * from DemoTable1351
-> group by StudentName
-> having count(StudentName) >=3;这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 2 | Bob | | 4 | David | +-----------+-------------+ 2 rows in set (0.00 sec)
热门推荐
10 简短创意祝福语有什么
11 年后祝福语简短走心
12 送离职同事简短祝福语
13 朋友结婚致辞祝福语简短
14 出院祝福语简短8字
15 父亲简短结婚祝福语大全
16 毕业结婚祝福语简短精辟
17 打游戏通关祝福语简短
18 姐妹结婚红包简短祝福语