Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SQL中查找某些值并显示不同字段中的相应值_Sql_Ms Access - Fatal编程技术网

在SQL中查找某些值并显示不同字段中的相应值

在SQL中查找某些值并显示不同字段中的相应值,sql,ms-access,Sql,Ms Access,所以我找到了这两篇文章,但它们并没有完全回答我的问题 我有一张这样的桌子 ID Type Date 1 Initial 1/5/15 1 Periodic 3/5/15 2 Initial 2/5/15 3 Initial 1/10/15 3 Periodic 3/6/15 4 5 Initial 3/8/15 ID

所以我找到了这两篇文章,但它们并没有完全回答我的问题

我有一张这样的桌子

ID      Type        Date
1       Initial      1/5/15 
1       Periodic     3/5/15
2       Initial      2/5/15  
3       Initial      1/10/15
3       Periodic     3/6/15  
4        
5       Initial      3/8/15
ID     Type    Date
1    Periodic  3/5/15
3    Periodic  3/6/15
4
我需要获得所有周期性或空的ID号以及相应的日期。所以我想得到一个如下的查询结果

ID      Type        Date
1       Initial      1/5/15 
1       Periodic     3/5/15
2       Initial      2/5/15  
3       Initial      1/10/15
3       Periodic     3/6/15  
4        
5       Initial      3/8/15
ID     Type    Date
1    Periodic  3/5/15
3    Periodic  3/6/15
4
我试过了

select id, type, date1
from Table1 as t
where type in (select type
               from Table1 as t2
               where ((t2.type) Is Null) or "" or ("periodic"));
但这不起作用。。。从我读到的关于NULL的内容来看,你不能比较NULL值。。。

所以我试过了

SELECT id, type, date1
FROM Table1 AS t
WHERE type in (select type
               from Table1 as t2
               where ((t.Type)<>"Initial"));
但这并没有给我4的身份证


有什么建议吗?

除非我遗漏了什么,否则你只需要:

select id, type, date1
from Table1 as t
where (t.type Is Null) or (t.type = "") or (t.type = "periodic");

or适用于布尔表达式,而不是要比较的值。

根据您的用户名,我猜正确的标记是ms-access。感谢您的回复!是的,但是如果我把4周期3/6/15和4周期3/6/15加在原始数据集中,我会得到4周期3/6/15和4。。。如果两者都有,我需要得到4个周期,3/6/15。。。这就是为什么我试着匹配他们。。。