题目: 在 MySQL 中有一张名为 t1 的表,其内容如下:

mysql> select * from t1;
c1
5,
NULL,
5,
NULL,
5,

5 rows in set (0.00 sec)

请给出以下 SQL 语句的结果:

  1. mysql> select avg(c1) as avg_num from t1;
  2. mysql> select count(*) from t1;
  3. mysql> select count(c1) from t1;

答案:

  1. mysql> select avg(c1) as avg_num from t1; 结果为:avg_num 为 5.0000

  2. mysql> select count(*) from t1; 结果为:count(*) 为 5

  3. mysql> select count(c1) from t1; 结果为:count(c1) 为 4

解释:

  • AVG(c1) 函数计算 c1 列的平均值,忽略 NULL 值。
  • COUNT(*) 函数计算表的总行数,包括 NULL 值。
  • COUNT(c1) 函数计算 c1 列中非空值的个数。
MySQL 单选题:计算平均值、总行数和非空值行数

原文地址: https://www.cveoy.top/t/topic/lDI6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录