-4

出于某种原因,这给了我一个空的结果。

Table
ppb_id     ppb_no ppb_date
100        1      (null)
100        2      2013-08-28 00:00:00
101        1      2013-08-28 00:00:00
101        2      2013-08-28 00:00:00

select ppb_id from ppb 
where (ppb_no = 1 and ppb_date is null) and (ppb_no = 2 and ppb_date is not null)

你能告诉我我做错了什么吗?

4

5 回答 5

4

I would change it to be:

select ppb_id from ppb 
where (ppb_no = 1 and ppb_date is null) or (ppb_no = 2 and ppb_date is not null)
于 2013-08-28T17:34:27.167 回答
2

You are saying you only want results where ppb_np = 1 AND ppb_date is null which = 1 result..

Then you say AND ppb_no = 2 and ppb_date is not null.

You may want to try OR since right now you basically are checking only 1 row after your AND

于 2013-08-28T17:35:04.387 回答
2

ppb_date can't be null and not null at the same time. It seems like you're looking for the OR operator:

select ppb_id from ppb 
where (ppb_no = 1 and ppb_date is null) OR 
      (ppb_no = 2 and ppb_date is not null)
于 2013-08-28T17:35:26.473 回答
1

I have strong reasons to believe that you need an OR instead of AND.

select ppb_id from ppb where (ppb_no = 1 and ppb_date is null) or 
(ppb_no = 2 and ppb_date is not null)
于 2013-08-28T17:35:10.587 回答
0

如果您需要两条记录 ppb_no = 1 ppb_no = 2,则应使用 OR 而不是 AND

于 2013-08-28T17:38:00.323 回答