現評級表pingji_table有三個字段 company_code,pingji,update_time
company_code 爲公司編碼,在該表中會重複出現
pingji 爲公司評級,不同年份評級可能不同
update_time 爲評級年份
現要求取出每個公司最新的評級:
select a.company_code,pingji from pingji_table a inner join
(select company_code,MAX(update_time) update_time from pingji_table group by company_code ) b
on a.company_code = b.company_code
and a.update_time = b.update_time