让我们首先创建一个表-
mysql> create table DemoTable -> ( -> ClientId int, -> Value int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(10,678); mysql> insert into DemoTable values(20,678); mysql> insert into DemoTable values(30,678);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+-------+ | ClientId | Value | +----------+-------+ | 10 | 678 | | 20 | 678 | | 30 | 678 | +----------+-------+ 3 rows in set (0.00 sec)
这是如果使用COUNT则对GROUP的查询不起作用-
mysql> select count(tbl.ClientId),max(tbl.ClientId) from DemoTable tbl -> group by Value;
这将产生以下输出-
+---------------------+-------------------+ | count(tbl.ClientId) | max(tbl.ClientId) | +---------------------+-------------------+ | 3 | 30 | +---------------------+-------------------+ 1 row in set (0.00 sec)