【问题标题】:MYSQL to display only the earliest of duplicates [duplicate]MYSQL仅显示最早的重复项[重复]
【发布时间】:2012-04-29 03:37:13
【问题描述】:
select name, reported_at from nodes
where reported_at < curdate() or reported_at is null
group by name

输出:

name                reported at
ncs-linux-test.edu  2012-03-16 18:36:03
ocdev1.net          2012-04-06 16:32:02
pinc-ctm.net        NULL

通过该声明,我会得到任何报告于/name 的结果表,但该表小于当前日期。

我需要的是只提取具有更多当前信息的重复数据的语句。

例如:

声明只会退出:

ncs-linux-test.edu    2012-03-16

如果有的话

ncs-linux-test.edu 

日期早于 2012-03-16。

【问题讨论】:

标签: mysql sql database


【解决方案1】:
select *
from nodes n 
join nodes nlater
  on n.name = nlater.name 
  and n.reportedat < nlater.reportedat

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    相关资源
    最近更新 更多