我正在使用 Python 并在 sqlite 中构建了一个表。我没有意识到 Python 有一个用于 sqlite 的时间戳字段类型,所以我将它存储为文本。下面是我的代码和结果.. 表中显示的唯一日期是 for2019-06-18但查询返回2019-06-19...不知道为什么import sqlite3# Connecting to the database filesqlite_file = 'insta.sqlite'conn = sqlite3.connect(sqlite_file)c = conn.cursor()# Get all rowsc.execute("SELECT * FROM daily_counts")count_row = c.fetchall()for row in count_row: print(row)# Get Daily Countc.execute('SELECT count FROM daily_counts where current_date = ? and client_id = ? and metric = ?', ('2019-06-18', 0, 'C'))count_row = c.fetchall()print(count_row)# Get Daily Countc.execute('SELECT count FROM daily_counts where current_date = ? and client_id = ? and metric = ?', ('2019-06-19', 0, 'C'))count_row = c.fetchall()print(count_row)# Get Daily Countc.execute('SELECT count FROM daily_counts where current_date = ? and client_id = ? and metric = ?', ('2019-06-20', 0, 'C'))count_row = c.fetchall()print(count_row)结果:(请注意,当条件为 19 时,它返回 18 的结果,而 18 则不返回任何结果..)(0, u'2019-06-18', u'A', 2)(0, u'2019-06-18', u'B', 6)(1, u'2019-06-18', u'C', 180)(1, u'2019-06-18', u'D', 258)(1, u'2019-06-18', u'E', 111)(0, u'2019-06-18', u'C', 180)(1, u'2019-06-18', u'F', 3)[][(180,)][]我假设我应该使用时间戳字段类型而不是文本?但我仍然希望这能奏效
添加回答
举报
0/150
提交
取消