SELECT
a.CompanyCode,
a.EPS,
a.AdjustDate,
a.EndDate,
MONTH(a.EndDate) as end_month,
IF
( @CompanyCode = a.CompanyCode AND @AdjustDate <> a.AdjustDate, @row_num := @row_num + 1, @row_num := 1 ) AS row_num,
@CompanyCode := a.CompanyCode,
@AdjustDate := a.AdjustDate
FROM
db_hs_data.LC_NewestFinaIndex a,
( SELECT @row_num := 0, @CompanyCode := 0, @AdjustDate := 0 ) n
WHERE AdjustDate >= DATE_SUB(curdate(),INTERVAL 5 YEAR)
ORDER BY a.CompanyCode, a.AdjustDate DESC