MariaDB root@(none):dyw> show tables; +----------------+ | Tables_in_dyw | +----------------+ | animals | | clone1_animals | | clone_animals | | dcount | | employees | | indextab | | person | | tbl | +----------------+ 8 rows in set Time: 0.035s
MariaDB root@(none):dyw> select * from animals; +----+---------+------+ | id | name | foot | +----+---------+------+ | 1 | dog | 4 | | 2 | cat | 4 | | 3 | chicken | 2 | | 15 | bird | 2 | +----+---------+------+ 4 rows in set Time: 0.028s
MariaDB root@(none):dyw> insert into animals(name,foot) values ('cat',4);
Query OK, 1 row affected
Time: 0.010s
MariaDB root@(none):dyw> select * from animals; +----+---------+------+ | id | name | foot | +----+---------+------+ | 1 | dog | 4 | | 2 | cat | 4 | | 3 | chicken | 2 | | 15 | bird | 2 | | 16 | cat | 4 | +----+---------+------+ 5 rows in set Time: 0.021s
SELECT COUNT(*) ... GROUP BY ... HAVING ... 語法計算重複紀錄。
MariaDB root@(none):dyw> select count(*) as repetitions,name,foot from animals gr
-> oup by name,foot having repetitions>1;
+-------------+------+------+
| repetitions | name | foot |
+-------------+------+------+
| 2 | cat | 4 |
+-------------+------+------+
1 row in set
Time: 0.040s