错误:

delete from student where
username in ( select username from student group by username having count(username)>1)
and id not in (select min(id) as id from student group by username having count(username)>1 )

正确:

delete from student where
username in (select username from ( select username from student group by username having count(username)>1) a)
and id not in ( select id from (select min(id) as id from student group by username having count(username)>1 ) b)