Python通过EXCEL生成SQL语句

网友投稿 686 2022-11-18

Python通过EXCEL生成SQL语句

Python通过EXCEL生成SQL语句

import pandas as pdclass SqlTest(object): def __init__(self): self.a = f"with a1 as ( " self.b = f")select count(*) from a1" self.df = pd.read_csv(r'D:\sql.csv', encoding='gb18030') self.text = " " def sqltest(self): df = self.df print(self.a) for index, row in df.iterrows(): if index != df.index[-1]: text = f"{self.text}select '{row[0]}.{row[1]}' as table_name,count(*) as count from '{row[0]}.{row[1]}' where dt ='{row[2]}'union on" print(text) else: text = f"{self.text}select '{row[0]}.{row[1]}' as table_name,count(*) as count from '{row[0]}.{row[1]}' where dt ='{row[2]}' " print(text) print(self.b)if __name__ == '__main__': t = SqlTest() t.sqltest()

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:node 项目loaderUtils.parseQuery() received a non-string value which can be problematic报错解决办法
下一篇:openGL投影矩阵(OpenGL Projection Matrix)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~