我无法将SQLite查询查询的结果附加到另一个表中。最后,我还想在查询结果中添加一个数据点,并将其附加到新表中。以下是我到目前为止的尝试表示:
import datetime
import sqlite3
createDb = sqlite3.connect(r'C:\test')
queryCurs = createDb.cursor()
def qryblock():
return queryCurs.execute('''SELECT DB.R,
DB.T,
DB.A
FROM DB.SAT SAT,
DB.I I
WHERE A.RECOR = T.RECOR AND
((A.DF Is Not Null) AND
(A.PF Is Null) OR
(A.DF Is Null) AND
(A.PF Is Null) AND
(A.P<{d '1999-09-09'}))''')
def addmonth(current_line):
queryCurs.execute('''INSERT INTO monthview (record, route, date, amt)
VALUES (?,?,?,?)''',(record, route, date, amt))
def main():
current_date = datetime.datetime.today()
todayslist = []
if current_date == firstbusinessday():
monthsblock = qryblock()
for line in monthsblock:
for datapoint in line:
todayslist.append(datapoint)
todayslist.append(current_date)
addmonth(todayslist)
todayslist = []
createDb.commit()
else:
pass
if __name__ == '__main__':
main()
是否有更有效的方法将查询中的每一行都添加到新表中?如果我想在将查询结果插入新表之前将当前日期附加到查询结果中的每一行,该怎么办?最后,假设我的查询中的记录的列表或元组与函数中的参数的顺序不同,以使它们进入新表。我该如何处理?