让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Number int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(20); mysql> insert into DemoTable values(20); mysql> insert into DemoTable values(10); mysql> insert into DemoTable values(30); mysql> insert into DemoTable values(10); mysql> insert into DemoTable values(10);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------+ | Number | +--------+ | 20 | | 20 | | 10 | | 30 | | 10 | | 10 | +--------+ 6 rows in set (0.00 sec)
以下是从单个列中选择计数值的查询-
mysql> select Number,count(*) from DemoTable group by Number;
这将产生以下输出-
+--------+----------+ | Number | count(*) | +--------+----------+ | 20 | 2 | | 10 | 3 | | 30 | 1 | +--------+----------+ 3 rows in set (0.00 sec)