Python 读取数据库生成excel
发布于 2021-05-13 21:40 ,所属分类:数据库和大数据技术学习资料
来首外国洗脑神曲提提神。干IT是最最无趣的,生活需要多点色彩。
SELECT person_name as 姓名,event_time::date as "日期",
min(event_time)as"到达",max(event_time)as"离开"FROM
"ac_event_201911"whereperson_id>0groupby
person_name,event_time::date
SELECT person_name as "姓名",event_time::date as "日期",min(event_time) as "到达",max(event_time) as "离开" FROM "ac_event_201911" where person_id>0 and event_time<'2019-11-26' group by person_name,event_time::date union
SELECT person_name as "姓名",event_time::date as "日期",min(event_time) as "到达",max(event_time) as "离开" FROM "ac_event_201910" where person_id>0 and event_time>'2019-10-25' group by person_name,event_time::date order by "姓名","日期" asc
import pandas as pd
importpsycopg2
def gg(query,file):
conn=psycopg2.connect(database="cmsdb",user="",password="",host="",port="")
#用户名,密码根据实际填
df = pd.read_sql_query(query, conn)
df.to_excel(file, index=False)
相关资源