表A
列:a1,a2
数据:1,2
1,2
表B
列:b1,b2,b3
数据:1,2,2008-01-01
1,2,2008-03-01
1,2,2008-02-25
查询结果
列为:a1,a2,b3
数据:1,2,2008-03-01b3为日期,这两表要通过前两列关联(必须有),取出b3距现在最近的日期,谢谢
列:a1,a2
数据:1,2
1,2
表B
列:b1,b2,b3
数据:1,2,2008-01-01
1,2,2008-03-01
1,2,2008-02-25
查询结果
列为:a1,a2,b3
数据:1,2,2008-03-01b3为日期,这两表要通过前两列关联(必须有),取出b3距现在最近的日期,谢谢
from
(
select a.a1,a.a2,b.b3
from a,b
where a.a1=b.b1 and a.a2=b.a2
order by b3 desc
)
where rownum=1
where exists(select 1 from a where a.a1=b.b1 and a.a2=b.b2)
group by b1,b2