T.ex.:
SELECT x.*
, CASE WHEN y.a_code = x.a_code THEN 1 ELSE 2 END level
FROM my_table x
LEFT
JOIN my_table y
ON y.e_id = x.e_id
AND y.a_code = x.a_code
AND y.date < x.date - INTERVAL 2 YEAR;
Name
ska inte vara en kolumn i den här tabellen.