求sql:得到的是每天a字段最大值和最大值的id、最小值值和最小值的id

select m.id, m.a, n.id, n.a  
from  
(select t0.* from t t0 
where not exists (select 1 from t t1 where t1.sj = t0.sj and t1.a > t0.a)) m 
select t0.* from t t0 where not exists (select 1 from t t1 where t1.sj = t0.sj and t1.a < t0.a)) n 
where m.sj = n.sj;
原文地址:https://www.cnblogs.com/kevinge/p/2128741.html