0

我想获得以下结构:

                 Day 1   |    2    |   3    | 4       ... Total
stackoverflow                04:00            01:00       05:00
google             05:30               02:00              07:30

但是使用我的代码,我得到:

                 Day 1   |    2    |   3    | 4      ...  Total
stackoverflow                04:00                        04:00
google             05:30                                  05:30
stackoverflow                                01:00        01:00
google                               02:00                02:00

我正在运行这个查询(在此处给出):

select 
  agenc.name, 
  sum(cast(servic.end_hour as time) - cast(servic.begin_hour as time)) as time_, jobs.description
from 
  services as servic  
  join services_jobs AS jobs ON jobs.id = servic.job_id  
  join agency as agenc ON agenc.id = jobs.agency_id
where  
  extract(month from servic.service_date) = 9 and  
  extract(day from servic.service_date) = 16
group by
  agenc.name

在 python 中,我执行相同的查询,不同之处在于查询“extract(day from service.service_date)”中的“day column”等于循环(从 1 到 31 -> 天数)

query_A = cr.fetchall()
    if query_A:
        for values in query_A:
            sheet.write(line_, 0, values[0], style_main) # Writes the name
            sheet.write(line_, 1, values[2], style_main) # Writes the job

            current_value = str(values[1]);
            hours_ = current_value.split(':')[0]
            minutes_ = current_value.split(':')[1]
            total_ = hours_ +':'+ minutes_ # This will get 02:00 - for example

            sheet.write(line_, i + 1, total_, style_main) # write the result
            total_vertical += timedelta(hours=int(hours_), minutes=int(minutes_)) # here should sum the results along the days
            sheet.write(line_, 33, str(total_vertical), style_main) # write it on "total" column    
            line_ += 1

            total_vertical = timedelta(hours=0, minutes=0) # Reset 

关于我应该如何继续获得我想要的结果的任何建议?谢谢!

4

1 回答 1

0

问题已解决,请查看以下链接中的代码:http: //pastebin.com/kcH1bTMp

于 2013-09-17T17:06:11.330 回答