年 产品 销量
2005 a 700
2005 b 550
2005 c 600
2006 a 340
2006 b 500
2007 a 220
2007 b 350
我要得到
2005 a 700
2006 b 500
2007 b 350
怎么做?
select * from tb a where not exists(select * from tb where 年=a.年 and 销量>a.销量)
--or:
select * from tb a inner join (select 年,max(销量) as 销量 from tb group by 年)b
on a.年=b.年 and a.销量=b.销量