특정 횟수만큼 나타나는 필드를 반환하는 구문은 다음과 같습니다. -
select distinct yourColumnName, count(yourColumnName) from yourTableName where yourColumnName LIKE 'J%' group by yourColumnName having count(*) > 1 order by yourColumnName;
먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1500 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.86 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
Mysql> insert into DemoTable1500 values(‘Adam’); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1500 values('John'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1500 values('Mike'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1500 values('John'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1500 values('Jace'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1500 values('Jace'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1500 values('Jackie'); Query OK, 1 row affected (0.06 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1500;
이것은 다음과 같은 출력을 생성합니다 -
+--------+ | Name | +--------+ | Adam | | John | | Mike | | John | | Jace | | Jace | | Jackie | +--------+ 7 rows in set (0.00 sec)
다음은 MySQL DISTINCT -
를 사용하여 특정 횟수만큼 나타나는 필드를 반환하는 쿼리입니다.mysql> select distinct Name, count(Name) -> from DemoTable1500 -> where Name LIKE 'J%' -> group by Name -> having count(*) > 1 -> order by Name;
이것은 다음과 같은 출력을 생성합니다 -
+------+-------------+ | Name | count(Name) | +------+-------------+ | Jace | 2 | | John | 2 | +------+-------------+ 2 rows in set (0.00 sec)