mysql> create table dfttst (a int null default null, b int null default 0,c int not null default 0); Query OK, 0 rows affected (0.07 sec)
mysql> insert into dfttst values (1,1,1),(null,null,null),(0,0,0); Query OK, 3 rows affected, 1 warning (0.01 sec) Records: 3 Duplicates: 0 Warnings: 1
mysql> show warnings; +---------+------+---------------------------+ | Level | Code | Message | +---------+------+---------------------------+ | Warning | 1048 | Column 'c' cannot be null | +---------+------+---------------------------+ 1 row in set (0.05 sec)
What is the result of the query below?
select count(a),count(b),count(c) from dfttst; a) 2,2,2 b) 3,3,3 c) 2,2,3
And still an extra question:
What would “select a + b + c from tt.dfttst;” return?
[ Data Types (15%) - Handling Missing or Invalid Data Values ]
Answer:
c
count(column-name)
returns the amount of non-NULL values for the column.a
andb
can contain NULL values, butc
can’t.Any calculation with
NULL
will result inNULL
.