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