如何消除特定记录并获得零记录&不是蜂巢中的无效记录
我有一个带有〜1k记录的桌子。我想基于1列消除特定的记录,该记录既具有零值,又不是空值。
我尝试了以下查询,但由于我是SQL的初学者,因此无法找到解决方案。
SELECT ID,Name,Dept,Location from db.sample where name<>'B';
通过使用上述查询,我不仅会收到空记录。但是我想获得“ B”记录以外的其他内容。
示例数据:
ID Name Dept Location
1 A Finance US
2 B Marketing UK
3 Transport China
4 C HR Canada
5 B Finance US
6 Production IND
输出:
ID Name Dept Location
1 A Finance US
3 Transport China
4 C HR Canada
6 Production IND
I have a table with ~1K records. I want to eliminate specific records based on 1 column which having both Null values and Not Null values.
I tried below query but I couldn't able to find the solution Since I'm beginner to SQL's.
SELECT ID,Name,Dept,Location from db.sample where name<>'B';
By using above query I'm getting Not Null records only. But I want to get other than 'B' records.
Sample Data:
ID Name Dept Location
1 A Finance US
2 B Marketing UK
3 Transport China
4 C HR Canada
5 B Finance US
6 Production IND
Output:
ID Name Dept Location
1 A Finance US
3 Transport China
4 C HR Canada
6 Production IND
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
name&lt;&gt; 'b'或名称为null
null始终将任何其他值(如false)比较,因此您必须使用“ nes null”或“ not is not Null”条件来明确处理它。
或者,您可以使用诸如cocece()之类的函数用其他值替换为null:
cocce(name,'x')&lt;&gt;&gt; 'B'
where name <> 'B' or name is null
NULL always compares to any other value as False, so you have to use the "is null" or "is not null" conditions to handle it explicitly.
Or you can use a function like coalesce() to replace NULL with some other value:
where coalesce(name, 'X') <> 'B'