sql 如何查询 空值的字段?

sql 如何查询 为空值的字段?
字段里面是空值,不是NULL
所以 像这样的 select count(id) from student where pwd is null 不能用

如何查询空值字段?

SQL NULL 值

    NULL 值代表遗漏的未知数据。

    默认地,表的列可以存放 NULL 值。

    如果表中的某个列是可选的,那么我们可以在不向该列添加值的情况下插入新记录或更新已有的记录。这意味着该字段将以 NULL 值保存。

    NULL 用作未知的或不适用的值的占位符。

    注释:无法比较 NULL 和 0;它们是不等价的。

    NULL 值的处理方式与其他值不同。

我们如何仅仅选取在 “Address” 列中带有 NULL 值的记录呢?

我们必须使用 IS NULL 操作符:

-from shulanxt

如果按照楼主的问题,利用 IS NULL 操作符是可以完成查询操作的,但是查询不出来可能是因为 pwd 字段是空格值,它的数据是已知的,就像“0”和“NULL”一样,所以建议去查看一下 pwd 字段的数据值的情况。

希望以上回答能对您有所帮助~望采纳~

温馨提示:内容为网友见解,仅供参考
第1个回答  2019-09-28

sql查询空值的字段写法:SELECT A.字段 FROM student  A WHERE A.字段 LIKE'% %' (student为表名)

查询类似空值的写法:

1、查询名称有退格键:select * from t_bd_item_info  where charindex(char(8),item_name) > 0 go

2、查询名称有制表符tab:select * from t_bd_item_info  where charindex(char(9),item_name) > 0 go

3、查询名称有换行:select * from t_bd_item_info where charindex(char(10),item_name) > 0 go

4、查询名称有回车:select * from t_bd_item_info where charindex(char(13),item_name) > 0 go

5、查询名称的空格(前空格、后空格、所有空格):select * from t_bd_item_info where isnull(charindex(' ',item_name),0) > 0 go

6、查询名称的单引号:select * from t_bd_item_info where charindex(char(39),item_name) > 0 go

7、查询名称的双单引号:select * from t_bd_item_info where charindex(char(34),item_name) > 0 go

扩展资料

1、处理名称有退格键
update t_bd_item_info set item_name = replace(item_name,char(8),'')
where charindex(char(9),item_name) > 0 go

2、处理名称有制表符tab
update t_bd_item_info set item_name = replace(item_name,char(9),'')
where charindex(char(9),item_name) > 0 go

3、处理名称有换行  
update t_bd_item_info set item_name = replace(item_name,char(10),'')
where charindex(char(10),item_name) > 0 go

4、处理名称有回车  
update t_bd_item_info set item_name = replace(item_name,char(13),'')
where charindex(char(13),item_name) > 0 go

5、处理名称的空格(前空格、后空格、所有空格)
update t_bd_item_info set item_name = replace(rtrim(ltrim(item_name)),' ','')  
where isnull(charindex(' ',item_name),0) > 0  go

6、处理名称的单引号
update t_bd_item_info set item_name = replace(item_name,char(39),'')
where charindex(char(39),item_name) > 0 go

7、处理名称的双单引号
update t_bd_item_info set item_name = replace(item_name,char(34),'')
where charindex(char(34),item_name) > 0 go

参考资料:百度百科-结构化查询语言(SQL)

本回答被网友采纳
第2个回答  2009-07-10
select count(id) from student where pwd = ''
第3个回答  2009-07-10
select count([id]) from student where pwd = ''
第4个回答  2009-07-10
select count(*) from student where pwd is null
相似回答