在两个标准之间返回多个列

2024-04-20 04:24:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含三列的SQLite数据库;名称、时间和日期。我正在尝试运行一个查询,该查询将返回包含EmpName和适合特定日期范围的时间的行。我的目标是把所有这些时间加起来,得出一个周末的总时间。但是,当我运行代码时,它返回一个0的列表

我尝试过以下查询:

SELECT * FROM Swipes WHERE theDate>=:starting<=:endof", {'starting': fstartingDate, 'endof': formatted}

SELECT EmpName AND theTime FROM Swipes WHERE theDate >=? <=?, (fstartingdate, formatted,)

SELECT EmpName AND theTime FROM Swipes WHERE thedate BETWEEN ? AND ?", (fstartingDate, formatted)

这种方法的其他变体,但感觉像是在兜圈子。 这是我的代码:

def weekSummary(endofthatweek):
    formatted = dt.strptime(endofthatweek, '%Y-%m-%d')
    startingDate = formatted - td(days=7)
    fstartingDate = startingDate.date()
    con = sqlite3.connect(r'C:\Users\zstrickland.RANDSMACHINE\Documents\PymeClock\testTimeclock.db')
    cur = con.cursor()
    cur.execute("SELECT EmpName AND theTime FROM Swipes WHERE theDate>=:starting<=:endof", {'starting': fstartingDate, 'endof': formatted})
    tupes = cur.fetchall()
    con.close()
    detuped = [x[0] for x in tupes]
    print(detuped)

我希望得到以下格式的列表(可能是元组列表…): [(EmpName,theTime),(EmpName,theTime),(EmpName,theTime),(EmpName,theTime)]。 任何关于如何进行此计算的帮助或建议都会有所帮助。谢谢大家!


Tags: andfrom列表时间whereconselectstarting