【发布时间】:2014-09-30 15:57:47
【问题描述】:
所以我为使用主电话和移动电话的客户准备了这张桌子。我要么有一个有效数字,要么有一个空格,要么有一个 NULL 值。
CustName MainPhone MobilePhone
Joe 800-111-1234 321-123-1234
Jack 321-321-1237
Jill
Jimmy 321-123-1234
James NULL 432-322-2222
所以我总共有 5 条记录,我想过滤掉在 Main 和 Mobile 上都有空白的 CustName。所以我首先检查了我有多少,并使用了这个 WHERE CLAUSE:
Select *
From MyTable
Where (MainPhone = '' and MobilePhone = '')
是的,这仅返回一条记录,在这种情况下,Jill 在任一字段中都没有数字。
现在,如果我想列出除 MainPhone 和 MobilePhone 上都有空格的记录之外的所有人,WHERE CLAUSE 会是什么样子?我尝试了一些变化,但没有得到正确的结果。
最终的结果应该是这样的
CustName MainPhone MobilePhone
Joe 800-111-1234 321-123-1234
Jack 321-321-1237
Jimmy 321-123-1234
James NULL 432-322-2222
谢谢
【问题讨论】:
-
你的意思是?
Where (MainPhone != '' and MobilePhone !='') -
你的意思是
Where (MainPhone != '' OR MobilePhone !='')来自简单地反转第一个查询:Where NOT (MainPhone = '' and MobilePhone = '')并应用 De morgan。 -
您在数据库中添加了 varchar "EmptySpace" 作为值?
-
@jENN,不,空格不是一个值,它只是说这个值是一个空格。我已经编辑了我的帖子以减少混乱。
标签: sql where-clause logical-operators