使用mysql查询在表中找到错误的条目

时间:2022-05-24 07:50:41

I have a table 'example' which looks like this

我有一个表'示例',看起来像这样

id index   date        number
============================
1   10   2016-01-01     26
2   10   2016-01-02     0
3   10   2016-01-03     26
4   11   2016-01-01     39

I wish to find the record which was updated wrongly. In this case it is the row with id 2(as you can see the next and previous date values for 'number' column are same for the query select * from example where index=10 order by date desc);

我希望找到错误更新的记录。在这种情况下,它是id为2的行(正如您可以看到'number'列的下一个和上一个日期值对于查询select * from example from index = 10 order by date desc)相同;

1 个解决方案

#1


0  

Your requirements are rather ambiguous so this is based on my assumptions of them.

您的要求相当模糊,因此这是基于我对它们的假设。

SELECT id, index, MIN(date) AS date, number
FROM example
WHERE index = 10
GROUP BY id, index, number

#1


0  

Your requirements are rather ambiguous so this is based on my assumptions of them.

您的要求相当模糊,因此这是基于我对它们的假设。

SELECT id, index, MIN(date) AS date, number
FROM example
WHERE index = 10
GROUP BY id, index, number