你可以使用子查询并进行简单的逻辑操作来实现这一点。
set @cnt=0;
set @id=-1;
SELECT
t3.id, t3.status, t3.dup_id AS `group`
FROM
(SELECT
id,
status,
IF(status = 0, @cnt:=@cnt + 1, @cnt:=0) AS great,
IF(@cnt = 1, @id:=id, IF(status = 0, @id, - 1)) AS dup_id
FROM
statuses) t3
WHERE
t3.dup_id IN (SELECT
t1.dup_id
FROM
(SELECT
id,
status,
IF(status = 0, @cnt:=@cnt + 1, @cnt:=0) AS great,
IF(@cnt = 1, @id:=id, IF(status = 0, @id, - 1)) AS dup_id
FROM
statuses) t1
GROUP BY t1.dup_id
HAVING COUNT(t1.dup_id) > 1
AND t1.dup_id != - 1);
结果将会如您所期望的那样。
id | status | group
----|--------|---------
443 | 0 | 443
323 | 0 | 443