0
有有DATETIME
场,我已经用Python创建了一个SQLite数据库:蟒蛇:在一个SQLite数据库查询DATETIME字段的日期范围
import sqlite3
con = sqlite3.connect('some.db',detect_types=sqlite3.PARSE_DECLTYPES)
with con:
cur = con.cursor()
cur.execute("CREATE TABLE Table(...Date DATETIME...)")
...
Date = datetime.datetime(<a format that resolves to the correct datetime object>)
...
altogether = (..., Date, ...)
cur.execute("INSERT INTO Table VALUES(...?...)", altogether)
con.commit()
这正确填充。后来我才希望能够通过日期时间查询这个数据库,并具有以下功能:一般管理我的疑问:
def query_db(path, query, args=(), one=False):
connection = sqlite3.connect(path)
cur = connection.execute(query, args)
rv = [dict((cur.description[idx][0], value)
for idx, value in enumerate(row)) for row in cur.fetchall()]
return (rv[0] if rv else None) if one else rv
LOCAL_FOLDER = os.getcwd()
samplequery = "SELECT * FROM Table"
dbFile = os.path.join(LOCAL_FOLDER, "some.db")
result = query_db(dbFile, samplequery)
以上会成功产生result
给了我在Table
一切。
但是,我怎么构建一个查询,将,例如,给我的所有条目在Table
表some.db
有在过去60天Date
?
所以,我们正在编辑的外观如下实际查询: '选择不同,,计数(1)为num从表组由,;'。 如果我们想要在过去的60天内过滤上述查询,我们会在哪里添加上述查询? –
fox