gpt4 book ai didi

python - 如何使用 Python 在 MYSQL DB 中选择最近 1 分钟的记录

转载 作者:行者123 更新时间:2023-11-28 23:14:16 24 4
gpt4 key购买 nike

我有一个像这样的 MYSQL 数据库表,

received_time    -    message
--------------------------------
08:20:30 - I'm happy with your service
08:20:33 - I'm your customer
08:21:40 - We hate about your customer service

我想选择最近一分钟内收到的消息。我使用了以下查询。

cursor = conn.cursor()
cursor.execute("SELECT Message FROM all_message WHERE received_time >= NOW() -INTERVAL 1 MINUTE")
results = [res[0] for res in cursor.fetchall()]
print results

但它返回空值。谁能帮我解决这个问题。

最佳答案

SELECT Message FROM all_message WHERE received_time >= DATE_SUB(NOW(),INTERVAL 1 MINUTE) 

您必须在插入记录后 1 分钟之前执行此查询。

试试上面的代码。

希望这会有所帮助。

关于python - 如何使用 Python 在 MYSQL DB 中选择最近 1 分钟的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44564486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com