mysql テーブル作成

create table test (id int auto_increment, key1 int, key2 int, created_at timestamp not null default current_timestamp, primary key (id));
update test set test.active = 1
where (id) in
(select id
from test
where (kr,created_at) in
(select kr, max(created_at) from test group by kr))