MySQL数据库中所有行的确切计数?
要精确计数所有行,您需要使用聚合函数COUNT(*)。语法如下-
select count(*) as anyAliasName from yourTableName;
为了理解上述语法,让我们创建一个表。创建表的查询如下-
mysql> create table CountAllRowsDemo -> ( -> Id int, -> Name varchar(10), -> Age int -> );
现在,您可以使用insert命令在表中插入一些记录。查询如下-
mysql> insert into CountAllRowsDemo values(1,'John',23); mysql> insert into CountAllRowsDemo values(101,'Carol',21); mysql> insert into CountAllRowsDemo values(201,'Sam',24); mysql> insert into CountAllRowsDemo values(106,'Mike',26); mysql> insert into CountAllRowsDemo values(290,'Bob',25); mysql> insert into CountAllRowsDemo values(500,'David',27); mysql> insert into CountAllRowsDemo values(500,'David',27); mysql> insert into CountAllRowsDemo values(NULL,NULL,NULL); mysql> insert into CountAllRowsDemo values(NULL,NULL,NULL);
使用select语句显示表中的所有记录。查询如下-
mysql> select *from CountAllRowsDemo;
以下是输出-
+------+-------+------+ | Id | Name | Age | +------+-------+------+ | 1 | John | 23 | | 101 | Carol | 21 | | 201 | Sam | 24 | | 106 | Mike | 26 | | 290 | Bob | 25 | | 500 | David | 27 | | 500 | David | 27 | | NULL | NULL | NULL | | NULL | NULL | NULL | +------+-------+------+ 9 rows in set (0.00 sec)
这是使用聚合函数count(*)来计算表中确切行数的方法。
查询如下-
mysql> select count(*) as TotalNumberOfRows from CountAllRowsDemo;
以下是带有行数的输出-
+-------------------+ | TotalNumberOfRows | +-------------------+ | 9 | +-------------------+ 1 row in set (0.00 sec)
热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短