count大揭秘

1:count(*) 和count(常量)统计所有行
count(常量)相当于每行增加一个常量字段
2:count(列名) 统计此列是非空的行
3:count(null) 恒等于 0

SQL> create table t1 as select * from dba_objects;

表已创建。

SQL> --统计所有行
SQL> select count(*) from t1;

  COUNT(*)
----------
     72752

SQL> --统计所有行
SQL> select count(1) from t1;

  COUNT(1)
----------
     72752

SQL> --统计所有行
SQL> select count('a') from t1;

COUNT('A')
----------
     72752

SQL> --统计非空行
SQL> select count(data_object_id) from t1;

COUNT(DATA_OBJECT_ID)
---------------------
                 7944

SQL> select count(null) from t1;

COUNT(NULL)
-----------
          0

SQL>

猜你喜欢

转载自blog.csdn.net/winer1220/article/details/79233976