AM使用mySQL 5,需要编写一个SQL语句(或存储的过程(如果需要(如果需要((,以删除该表的所有重复行,除了最近的一行(最年轻的created_time((?
这是表:
desc user_detail;
屈服:
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------------------+-----------------------------+
| user_id | varchar(200) | NO | PRI | | |
| device | text | YES | | NULL | |
| created_time | timestamp | NO | | 0000-00-00 00:00:00 | |
| updated_time | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
这可以通过exists
自加入:
delete from user_detail a where exists (
select 1 from user_detail b
where a.device = b.device
and b.created_time > a.created_time
)