(select b.a_id,b.fd1,b.fd2
from b,
(select a_id,max(b_order) as max_b_order from b group by a_id) as bmax
where b.a_id=bmax.a_id and b.b_order=bmax.max_b_order) as t1,
(select b.a_id,b.fd1,b.fd2
from b,
(select a_id,min(b_order) as min_b_order from b group by a_id) as bmin
where b.a_id=bmin.a_id and b.b_order=bmin.min_b_order) as t2
where a.a_id = b.a_id and a.a_id = t1.a_id and a.a_id = t2.a_id
其中:
1. (select a_id,max(b_order) as max_b_order from b group by a_id) as bmax
得到b_order较大的那些记录的a_id和b_order.
2. (select b.a_id,b.fd1,b.fd2
from b,
(select a_id,max(b_order) as max_b_order from b group by a_id) as bmax
where b.a_id=bmax.a_id and b.b_order=bmax.max_b_order) as t1,
得到b_order较大的那些记录的a_id和fd1,fd2