MySQL清单中特定项目的不同数量
要查找不同数量的特定项目,请COUNT()与GROUPBY子句一起使用。让我们首先创建一个表-
mysql> create table DemoTable1854
(
Name varchar(20)
);使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1854 values('John-Smith');
mysql> insert into DemoTable1854 values('Chris-Brown');
mysql> insert into DemoTable1854 values('Adam-Smith');
mysql> insert into DemoTable1854 values('John-Doe');
mysql> insert into DemoTable1854 values('John-Smith');使用select语句显示表中的所有记录-
mysql> select * from DemoTable1854;
这将产生以下输出-
+-------------+ | Name | +-------------+ | John-Smith | | Chris-Brown | | Adam-Smith | | John-Doe | | John-Smith | +-------------+ 5 rows in set (0.00 sec)
这是获取列表中特定项目的不同数量的查询-
mysql> select Name,count(Name) from DemoTable1854
where Name like 'John-%'
group by Name;这将产生以下输出-
+------------+-------------+ | Name | count(Name) | +------------+-------------+ | John-Smith | 2 | | John-Doe | 1 | +------------+-------------+ 2 rows in set (0.00 sec)
热门推荐
10 祖国生日简短祝福语大全
11 学弟英语高考祝福语简短
12 小孩生日祝福语简短励志
13 10岁高考祝福语简短
14 朋友的孩子祝福语简短
15 简单生日祝福语简短大全
16 元旦祝福语的英文简短
17 艺校元旦祝福语大全简短
18 中秋祝福语简短有深度