仅计算两个不同列中的空值,并在一个MySQL select语句中显示?
使用ISNULL测试NULL值。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Number1 int, -> Number2 int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(1,NULL); mysql> insert into DemoTable values(NULL,NULL); mysql> insert into DemoTable values(3,NULL); mysql> insert into DemoTable values(NULL,90);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
这将产生以下输出-
+---------+---------+ | Number1 | Number2 | +---------+---------+ | 1 | NULL | | NULL | NULL | | 3 | NULL | | NULL | 90 | +---------+---------+ 4 rows in set (0.00 sec)
以下是仅计算两个不同列中的空值并在一个select语句中显示的查询-
mysql> select -> (select count(*) from DemoTable where Number1 is null) as FirstColumnNullValue, -> (select count(*) from DemoTable where Number2 is null) as SecondColumnNullValue -> ;
输出结果
这将产生以下输出-
+----------------------+-----------------------+ | FirstColumnNullValue | SecondColumnNullValue | +----------------------+-----------------------+ | 2 | 3 | +----------------------+-----------------------+ 1 row in set (0.00 sec)