我有以下数据
ID Status W_ID
1 In Progress 7
2 In Progress 5
3 Complete 5
4 In Progress NULL
5 Complete 7
我希望选择记录状态为“进行中”,W_ID为NULL或W_ID为5
结果就像
ID Status W_ID
2 In Progress 5
4 In Progress NULL
我应该如何编写选择查询?
答案 0 :(得分:0)
尝试如下,非常简单,您必须应用'和' &安培; '或'条件。
Select * from table where Status = 'In Progress' and (W_ID is NULL or W_ID = 5)
答案 1 :(得分:0)
WHERE Status = 'In Progress' AND (W_ID IS NULL OR W_ID = 5)
或者
WHERE Status = 'In Progress' AND ISNULL(W_ID,5)= 5
答案 2 :(得分:0)
尝试以下查询,它以状态
的状态获取正在进行的记录SELECT * FROM Table WHERE Status ='In Progress' AND (ISNULL(W_ID,0) = 0 OR ISNULL(W_ID,0) = 5)