mysql多字段group的替代方法

現評級表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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章