Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash MySQL将根据给定参数显示最早的副本_Bash_Mysql_Sql - Fatal编程技术网

Bash MySQL将根据给定参数显示最早的副本

Bash MySQL将根据给定参数显示最早的副本,bash,mysql,sql,Bash,Mysql,Sql,我需要声明做的是: 从名称中,输出具有最早日期的重复数据 例如: 如果存在日期为2012年4月2日的mich.edu和日期为2012年4月1日的mich.edu,我希望该语句仅输出日期为2012年4月1日的mich.edu 以下是我的声明: echo "select name, reported_at from nodes where reported_at < curdate() or reported_at is null;" | mysql dashboard 听起来您需要: ec

我需要声明做的是:

  • 从名称中,输出具有最早日期的重复数据
  • 例如:

    如果存在日期为2012年4月2日的mich.edu和日期为2012年4月1日的mich.edu,我希望该语句仅输出日期为2012年4月1日的mich.edu

    以下是我的声明:

    echo "select name, reported_at from nodes where reported_at < curdate() or reported_at is null;" | mysql dashboard
    
    听起来您需要:

    echo“从节点中选择name,min(reported_at),其中reported_at
    选择name,reported_at from节点,其中reported_at

    可能也适用于您,因为order by比较的是日期,而不是字符串(min仍然这样做)

    order by
    子句应该在
    group by
    子句之后。
    name            reported_at
    ngsghsdfg.edu   2012-03-23 03:40:04
    wasdfas.edu 2012-03-05 17:42:03
    cnadfafg.uiowa.edu  NULL
    qwerqwer.edu    2012-03-19 17:03:03
    qwerqwre.edu    2012-03-30 20:04:02
    qewrqwre.uiowa.edu  2012-03-24 16:10:02
    qwerqewr.edu    2012-03-23 22:12:05
    qwrewqreq.uiowa.edu NULL
    qwerwqer.edu    2012-04-01 04:18:05
    adfgnafg.edu    2012-03-27 18:21:01
    adsfasf.edu         NULL
    
    echo "select name, min(reported_at) from nodes where reported_at < curdate() or reported_at is null group by name;" | 
    mysql dashboard
    
    select name, reported_at from nodes where reported_at < curdate() or reported_at is null order by reported_at desc group by name ;