sqlselect,每分钟只有一条记录

new9mtju  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(356)

我在php中使用了sql select,如下所示:

$sql_GATE  = $conn->query("SELECT  * FROM GATE WHERE st='ff0000' and dataGate between '2018-06-27 00:00:0' and '2018-06-27 23:59:0' order by id desc ");

此代码返回给我大约120000条记录,例如:

1-ff0000-->2018-06-27 18:28:51<br>
2-ff0000-->2018-06-27 18:28:51<br>
3-ff0000-->2018-06-27 18:28:51<br>
13-ff0000-->2018-06-27 18:28:49 .......

如何编写每1分钟或2分钟仅返回一条记录的sql请求?因为一秒钟就有三张唱片

nr7wwzry

nr7wwzry1#

这里有语法和示例:

SELECT col1, col2, col3, colN, MAX(TimeAndDateColumn)
FROM table
GROUP BY DATE(TameAndDateColumn), HOUR(TimeAndDateColumn), Minute(TimeAndDateColumn)

例子:

SELECT id, latitute, longitude, speed, MAX(`time`)
FROM YourTableName
GROUP BY DATE(`time`), HOUR(`time`), Minute(`time`)

相关问题