我在PHP中选择了这样的SQL:
$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 .......
如何编写SQL请求,每1分钟仅返回一条记录 还是2分钟?因为在一秒钟内大约有3条记录
答案 0 :(得分:1)
这里有语法和示例:
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`)