我很难在最长期限记录后记录最老/最小记录。
示例:
Status Date Active 8-1-2013 Active 7-2-2013 Active 6-1-2012****this is the date I need Term 5-30-2012 Active 4-12-2012 Term 3-5-2012
你有什么建议吗?
答案 0 :(得分:2)
如果我理解正确的话,
select min(Date) from table where status = 'Active' and Date >
(select max(Date) from table where Status = 'Term')
答案 1 :(得分:0)
这是在MySQL中有效的语法:
select t.*
from t
where t.date > (select MAX(t.date) from t where status = 'TERM')
order by date
limit 1;
在其他数据库中,limit 1
可能是select top 1
或where rownum = 1
,甚至可能是其他内容。
如果您只想要日期,那么您可以使用1_CR的解决方案。