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)
if __name__ == '__main__':
t = SqlTest()
t.sqltest()