select 年,产品,销量=max(销量) 
from tb
group by 年,产品

解决方案 »

  1.   


    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.销量
      

  2.   

    觉得sql在分组这方面的能力好差.比如说, 现在我们按某些字段对数据表进行分组.
    然后想得到每组的第三条记录(已知,每组的记录数至少有三条)如果想求解这种问题的话,那将是很麻烦的事情.
    当然你可以通过为每组的记录加一个排序列.
    但是总觉得用起来不顺手.