create table test77(djbh varchar(10),spdm varchar(10),sl int) insert into test77 values('JA001','a',4) insert into test77 values('JA001','b',3) insert into test77 values('JA002','a',5) insert into test77 values('JA003','a',2) insert into test77 values('JA004','a',2) insert into test77 values('JA005','a',2) insert into test77 values('JA006','a',2)
select max(djbh) from test77 a where 17>= (select sum(sl) from test77 b where a.djbh > b.djbh and a.spdm = b.spdm) and spdm = 'a'
这种语法很奇怪,想不明白..