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
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 ;