먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1453 -> ( -> CustomerId int, -> CustomerReviewNumber int -> ); Query OK, 0 rows affected (0.58 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1453 values(10,4); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1453 values(10,4); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1453 values(11,5); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1453 values(11,5); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable1453 values(11,5); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable1453 values(13,2); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1453 values(11,5); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1453 values(10,4); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1453 values(13,2); Query OK, 1 row affected (0.14 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1453;
이것은 다음과 같은 출력을 생성합니다 -
+------------+----------------------+ | CustomerId | CustomerReviewNumber | +------------+----------------------+ | 10 | 4 | | 10 | 4 | | 11 | 5 | | 11 | 5 | | 11 | 5 | | 13 | 2 | | 11 | 5 | | 10 | 4 | | 13 | 2 | +------------+----------------------+ 9 rows in set (0.00 sec)
다음은 중복 ID를 계산하는 쿼리입니다 -
mysql> select CustomerId,count(distinct CustomerReviewNumber) -> from DemoTable1453 -> group by CustomerId;
이것은 다음과 같은 출력을 생성합니다 -
+------------+--------------------------------------+ | CustomerId | count(distinct CustomerReviewNumber) | +------------+--------------------------------------+ | 10 | 1 | | 11 | 1 | | 13 | 1 | +------------+--------------------------------------+ 3 rows in set (0.14 sec)