# 查询当前时间之前X分钟

很多时候需要查询当前时间之前的时间到当前的数据，可以通过mysql的 `data_sub` 函数来设置一个间隔时间获得：

```
select * from test_table where count_time > date_sub(now(), interval 1 minute) ;
```

以上查询就是 `test_table` 的 `count_time` 字段中，一分钟以内数据查询。

## 参考

* [How to select last 3 minutes' records from MySQL with PHP](https://stackoverflow.com/questions/7553346/how-to-select-last-3-minutes-records-from-mysql-with-php/7553354#comment43101603_7553354)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/database/mysql/sql/select_current_and_minutes_ago.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
