select id,max_a,max_date,min_a,min_a_date
from test t
where not exists(select 1 from test t1
where t.id=t1.id and t.max_a<t1.max_a and t.min_a>t1.min_a)
[/Quote]
如果要和表sal表关联,就是说如果sal表中的id=test表中的id相等才求max_a,max_date,min_a,min_a_date
该如何写呢?
sal表如下:
s_id
1
2
3
select id,max_a,max_date,min_a,min_a_date
from test t
where not exists(select 1 from test t1
where t.id=t1.id and t.max_a<t1.max_a and t.min_a>t1.min_a)