//取价格相近的 1500基准
drop table yscjg
create table yscjg(
ID int identity,
bm varchar(20),
mc varchar(20),
fs int,
jg int
)
insert into yscjg (bm,mc,fs,jg) values('09022315037294','金华日报印刷厂',1000,8000)
insert into yscjg (bm,mc,fs,jg) values('09022315037294','金华日报印刷厂',2000,7500)
insert into yscjg (bm,mc,fs,jg) values('09022315037294','金华日报印刷厂',3000,6000)
insert into yscjg (bm,mc,fs,jg) values('09022414037301','金华ABC广告制作公司',1000,8500)
insert into yscjg (bm,mc,fs,jg) values('09022414037301','金华ABC广告制作公司',2000,7500)
insert into yscjg (bm,mc,fs,jg) values('09022414037301','金华ABC广告制作公司',3000,7000)
select bm,mc,fs,jg from (select *,abs(fs-1500) as fs2 from yscjg ) as a
where (select Count(1) from yscjg b where a.bm=b.bm and a.jg < b.jg ) =1
order by bm,fs2,jg