【发布时间】:2017-02-04 21:09:58
【问题描述】:
我的 MySQL 数据库中有下表:
| id | teplota | created_at |
|---|---|---|
| 1 | 12.521 | 2017-02-01 17:49:53 |
| 1 | 12.852 | 2017-02-02 17:50:53 |
| 1 | 12.852 | 2017-02-03 17:50:53 |
| ... | ... | ... |
created_at 列的类型为时间戳,这是我的CREATE TABLE 语句中的列定义:
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
当我在 DB 中使用此选择命令时,它通常可以工作并且我得到正确的输出
select * from ts2 where created_at >= "2017-02-01" and created_at < "2017-02-02"
但如果我想在我的 python 代码中使用它,我有一个问题:
import datetime
t1 = datetime.datetime(2017, 2, 1)
t2 = datetime.datetime(2017, 2, 2)
t1 = str(t1)
t2 = str(t2)
c.execute("select * from ts2 where created_at >= %s and created_at < %s;" % (t1, t2))
我收到以下错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '00:00:00 和 created_at
知道我可能做错了什么吗? 谢谢
【问题讨论】:
-
在执行和发布前打印查询