import pandas as pd
class 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
Python通过EXCEL生成SQL语句
最新推荐文章于 2024-08-31 16:44:47 发布