其他分享
首页 > 其他分享> > break用法

break用法

作者:互联网

break用法:循环的时候,循环一次即停止

import pymysql,xlwt

FI = pymysql.connect(
   host='192.168.1.10',user='root',passwd='zentao_123',
   port=3306,db='zentao',charset='utf8'
   #port必须写int类型,
   #charset这里必须写utf8
)
cur = FI.cursor() #建立游标
sql = '''select
case left(d.name,2) when 'DD' then '调度' when 'DW' then '电网' when 'ZN' then '智能设备' when 'DL' then '智能设备' WHEN 'HB' then '华北' when 'ZH' then'综合能源'  when 'DS' then '大数据' when 'XS' then '智能线损' else '研发中心' end as 所属部门,
d.name as 项目,
b.realname,
 a.date,
 a.consumed as 工时,
 a.work
FROM zt_effort a
left join zt_user b on a.account=b.account
left join zt_dept c on b.dept=c.id
left join zt_project d on a.project=d.id
left join zt_task e on a.objectID=e.id
where c.id in (35,22,1)
and a.date >='20201226' and a.date <='20210625' and c.name='质量保障巴' and a.consumed>0
and b.realname  in ('赵博','郝楠','李青云','张红运','刘通慧','周蕊','于萍','郝楠','赵康')
and d.name not in  ('YFZX-技术研发中心公共管理工作','自动化测试脚本开发')
ORDER BY d.name,a.date'''
cur.execute(sql)
book=xlwt.Workbook()
sheet = book.add_sheet('调')
fileds=[filed[0] for filed in cur.description]#获取字段表头
res = cur.fetchall()  #获取所有返回的结果
for col, filed in enumerate(fileds):
    # print(col, filed)
    sheet.write(0, col, filed)
# book.save('./user_info.xls')
n=1
for i in res:
    bm=i[0]
    bm=bm[0:4]
    if bm=='调度':
        for j in range(len(i)):
            sheet.write(n, j, i[j])
            print(n,j,i[j])
        # break
    n+=1
book.save(r'C:\Users\zr\Desktop\11.xls')

  

标签:cur,name,when,用法,break,filed,zt,left
来源: https://www.cnblogs.com/ruijie/p/14931847.html