查询test_id为null 的所有数据(注意是null),返回结果中 把 test_id 为空字符串的数据不会显示出来
select* from test_table whereisnull(test_id);
判断test_id 为null 的另一种写法
select* from test_table where test_id isnull;
查询test_id 不为null 的所有数据,结果中会把 test_id 为空字符串的数据,及test_id有数据的所有数据全部查出来
select* from test_table where test_id is notnull;
查询test_id 不为null 的所有数据,返回结果中会把 test_id 为空字符串的数据,及test_id有数据的所有数据全部查出来,因为isnull()判断为空时,如果为空,返回1,如果是有值,或者空字符串,返回0
select* from test_table whereisnull(test_id)=0;
注:上面这两条SQL查询出来的结果是一样的
同时过滤掉test_id值为null,及空字符串的数据,返回结果中只显示test_id有数据的结果集
select* from test_table whereISNULL(test_id)=0ANDLENGTH(TRIM(test_id))>0 order by update_time desc;
另一种写法
select test_table,lesson_id from test_table wherecase when(ISNULL(test_id)=1)||(LENGTH(TRIM(test_id))=0) then'11' end;