【发布时间】:2017-11-01 14:03:50
【问题描述】:
所以我找到了这两篇文章,但它们并没有完全回答我的问题......
Find max value and show corresponding value from different field in SQL server
Find max value and show corresponding value from different field in 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
我需要获取所有“定期”或 NULL 的 ID 号和相应的日期。所以我想要一个看起来像这样的查询结果......
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 值... Why in SQL NULL can't match with NULL?
所以我尝试了
SELECT id, type, date1
FROM Table1 AS t
WHERE type in (select type
from Table1 as t2
where ((t.Type)<>"Initial"));
但这并没有给我 4 的 ID...
有什么建议吗?
【问题讨论】:
-
根据你的用户名,我猜正确的标签是 ms-access。