【问题标题】:find wrong entry in a table using mysql query使用 mysql 查询在表中查找错误条目
【发布时间】:2016-06-14 13:16:27
【问题描述】:

我有一个看起来像这样的表格“示例”

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

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

【问题讨论】:

  • 为什么错的是 3 而不是 4?
  • “你可以看到下一个和上一个日期值是相同的”我不能
  • select * from example where index=10 order by date desc;在这里,id 2 的值 'number' 不同
  • 所以要正确的行数必须与具有相同索引的其他行数相同?否则我仍然看不到如何发现错误的数据
  • 这里,id 2 的值 'number' 不同 那么为什么id = 3 又错了呢?

标签: mysql sql database sqlyog


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 2021-11-20
    • 2012-10-08
    • 1970-01-01
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多