MySQL 单选题:计算平均值、总行数和非空值行数
题目:
在 MySQL 中有一张名为 t1 的表,其内容如下:
mysql> select * from t1;
c1
5,
NULL,
5,
NULL,
5,
5 rows in set (0.00 sec)
请给出以下 SQL 语句的结果:
mysql> select avg(c1) as avg_num from t1;mysql> select count(*) from t1;mysql> select count(c1) from t1;
答案:
-
mysql> select avg(c1) as avg_num from t1;结果为:avg_num为 5.0000 -
mysql> select count(*) from t1;结果为:count(*)为 5 -
mysql> select count(c1) from t1;结果为:count(c1)为 4
解释:
AVG(c1)函数计算c1列的平均值,忽略 NULL 值。COUNT(*)函数计算表的总行数,包括 NULL 值。COUNT(c1)函数计算c1列中非空值的个数。
原文地址: https://www.cveoy.top/t/topic/lDI6 著作权归作者所有。请勿转载和采集!