这个表连接的语句该怎么写?

表a:
xh(序号) xm(姓名) .....
1 xxxx
表b:
xh(序号) sj(时间) nr(内容)
1 5-19 xxxx
1 5-20 xxxx
1 5-21 xxxx

挑出表b中离现在时间最近的记录,与表a连接,SQL语句该怎么写?
---------------------------------------------------------------

select * from tablea as a
inner join
(select xh,sj,nr from tableb b1 where sj=(select max(sj) from tableb where xh=b1.xh)) as b
on a.xh=b.xh

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus