MySQL中水平自连接表当前行和下一行

Sat*_*ati 0 mysql

我正在实现一个功能,其中我必须根据同一表的下一行中存在的值删除当前行。

我有包含以下列的记录:idcreated_atmark

我需要删除所有记录,

WHERE currentrow.mark != nextrow.mark or (currentrow.mark = nextrow.mark and currentrow.created_at= '2000-01-01 00:00:00.000')
Run Code Online (Sandbox Code Playgroud)

即只有下一行的记录具有不同的标记或下一行的记录具有相同的标记并且created_at = '2000-01-01 00:00:00.000'

id      created_at                  mark
235    1990-01-01 00:00:00.000      5                  /delete
236    1990-01-01 00:00:00.000      5                  /delete
237    1990-01-01 00:00:00.000      5
238    2016-10-10 23:45:40.000      5


id       created_at                 mark
312    1990-01-01 00:00:00.000      8                  /delete
313    2016-01-09 18:00:00.000      6                  
314    1990-01-01 00:00:00.000      4                  /delete
315    1990-01-01 00:00:00.000      7
316    2016-10-10 23:45:40.000      7
Run Code Online (Sandbox Code Playgroud)

请帮助检索结果集中水平连接同一表的下一行的每一行的表。

小智 5

连接下一行的一种方法是

INNER JOIN `tablename` AS `next` ON `next`.`id` = (
  SELECT MIN(id) FROM `tablename` WHERE `tablename`.`id` > `current`.`id`
)
AND (`next`.`mark` != `current`.`mark` 
  OR `next`.`created_at` = '2000-01-01 00:00:00.000') // maybe 1990?
Run Code Online (Sandbox Code Playgroud)