用于计算给定数据库中员工的总工作时间的python代码

时间:2013-11-05 14:52:59

标签: sql python-2.7

帮帮我

我有3列[empid in integer,flag in integer(1表示输入,0表示输出)&字符串格式的日期时间(即u'Thu,2013年10月3日17:35:43 +0000)]     我想知道如何编写代码或算法来获取in_time&使用变量计数的特定日期的out_time。这意味着,当数量是偶数时,它会给我in_time&当计数会增加时,它会给我out_time for odd。这里有一些我试过的代码。

conn = sqlite3.connect('/home/Documents/attendance_report/data.db')
c = conn.cursor()
c.execute('select * from attendance where emp = 95')
count = 0

for row in c:
   count +=1
   print row

1 个答案:

答案 0 :(得分:0)

您可以使用内置enumerate来跟踪索引。

for index, row in enumerate(c):
    if index%2 == 0: # Odd numbered row (since index starts from 0)
        # row contains out_time
        print row
    else:
        # row contains in_time
        print row