count_sum_distinct與null
SQL> create table t_agg(a int,b int,c int);
Table created
SQL> insert into t_agg values(1,null,1);
1 row inserted
SQL> insert into t_agg values(1,2,null);
1 row inserted
SQL> insert into t_agg values(2,1,null);
1 row inserted
SQL> insert into t_agg values(2,null,null);
1 row inserted
SQL> insert into t_agg values(3,4,8);
1 row inserted
SQL> commit;
Commit complete
SQL> select * from t_agg;
A B C
--------------------------------------- --------------------------------------- ---------------------------------------
1 1
1 2
2 1
2
3 4 8
SQL> select count(b),count(c) from t_agg group by a;
COUNT(B) COUNT(C)
---------- ----------
1 1
1 0
1 1
SQL> select a,count(b),count(c) from t_agg group by a;
A COUNT(B) COUNT(C)
--------------------------------------- ---------- ----------
1 1 1
2 1 0
3 1 1
SQL> truncate table t_agg;
Table truncated
SQL> insert into t_agg(a,b) values(1,null);
1 row inserted
SQL> insert into t_agg(a,b) values(1,1);
1 row inserted
SQL> insert into t_agg(a,b) values(1,1);
1 row inserted
SQL> insert into t_agg(a,b) values(2,1);
1 row inserted
SQL> insert into t_agg(a,b) values(2,2);
1 row inserted
SQL> insert into t_agg(a,b) values(3,1);
1 row inserted
SQL> commit;
Commit complete
SQL> select * from t_agg;
A B C
--------------------------------------- --------------------------------------- ---------------------------------------
1
1 1
1 1
2 1
2 2
3 1
6 rows selected
SQL> select a,count(distinct b) from t_agg group by a;
A COUNT(DISTINCTB)
--------------------------------------- ----------------
1 1
2 2
3 1
SQL> truncate table t_agg;
Table truncated
SQL> insert into t_agg(a) values(null);
1 row inserted
SQL> insert into t_agg(a) values(null);
1 row inserted
SQL> commit;
Commit complete
SQL> select count(a) from (select distinct a as a from t_agg);
COUNT(A)
----------
0
小結:count,sum,distinct忽略null,不計算在內
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-755305/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- not null與check is not nullNull
- mysql探究之null與not nullMySqlNull
- undefined與null與?. ??UndefinedNull
- MySQL案例-TIMESTAMP NOT NULL與NULLMySqlNull
- null與indexNullIndex
- NULL與索引Null索引
- null與substrNull
- NULL與排序Null排序
- NULL 值與索引Null索引
- NULL 值與索引(二)Null索引
- Null 與 “” 的區別Null
- “NOT_IN”與“NULL”的邂逅Null
- ((NULL) null).printNULL();((NULL) null).printnull();Null
- JavaScript undefined與null區別JavaScriptUndefinedNull
- undefined與null的區別UndefinedNull
- 索引與null(一):單列索引索引Null
- 索引與null(二):組合索引索引Null
- Object-C之(Null)與(Bool)ObjectNull
- Oracle空串與null的處理OracleNull
- IS NULL和IS NOT NULLNull
- mysql中null與“空值”的坑MySqlNull
- python None與Null 的區別PythonNoneNull
- MySQL裡null與空值的辨析MySqlNull
- 【問題處理】“NOT IN”與“NULL”的邂逅Null
- 了不起的 “filter(NULL IS NOT NULL)”FilterNull
- MySQL中is not null和!=null和<>null的區別MySqlNull
- in、exists操作與null的一點總結Null
- 理解:MySQL的null與空字串的不同MySqlNull字串
- oracle sql_not exists與null的測試OracleSQLNull
- oracle group by與分組列為null空OracleNull
- 索引裡的NULL值與排序小記索引Null排序
- oracle之''空子符串與NULL是否相等OracleNull
- where語句中多條件查詢欄位NULL與NOT NULL不確定性查詢Null
- 【NULL】Oracle null值介紹NullOracle
- Difference between 2>&-, 2>/dev/null, |&, &>/dev/null, >/dev/null, 2>&1devNull
- PHP7 ?? 與 ?: 的作用和區別(null合併運算子, null條件運算子)PHPNull
- JS中判斷null、undefined與NaN的方法JSNullUndefinedNaN
- Hashtable/HashMap與key/value為null的關係HashMapNull