使用上面的代码,我目前正在尝试实现以下结果:
Day: 1 | 2 | 3 | 4 ...etc
____________________________________________________
Google 00:00 09:22 00:00 00:00
Stack 01:00 00:00 03:00 00:00
line_ = 6
col_ = 2
for i in range(1, 32): # From Day 1 to Day 31
cr.execute("SELECT enti.entity, servic.hour_begin " \
"FROM services AS servic " \
"JOIN alljobs AS jobs ON jobs.id = servic.job_id " \
"JOIN entities AS enti ON enti.id = jobs.entity_id" \
"WHERE servic.create_uid = %s AND " \
"EXTRACT(MONTH FROM servic.date_registered) = %s AND " \
"EXTRACT(DAY FROM servic.date_registered) = %s",[5, 9, i])
# The values: 5 and 9, will be different..is just for testing
value = cr.fetchall()
if value:
for values in value:
#sheet.write(line_, 0, values[0], style_main)
sheet.write(line_, col_, values[1], style_main)
col_ += 1
else:
sheet.write(line_, col_, '00:00', style_main)
col_ += 1
if i == 31:
col_ = 2
line_ += 1
虽然,代码重现了下表:
Day: 1 | 2 | 3 | 4 ...etc
01:00 09:22 03:00 00:00
查询可以显示很多结果,因为一天可以做很多服务,所以我做了第二个循环。谢谢。