select * from (select distinct code , min(cost) mcost from xx group by code) a
left join xx b on a.code=b.code and a.mcost= b.cost
---------------
那就
select a.code,a.x1,a.x2,a.x3,b.mcost as cost from xx a
left join (select distinct code , min(cost) mcost from xx group by code) b on a.code=b.code