一、目的
1.已知表名,批量书写以及拼接sql进行取数;
二、实施
df=pd.read_excel(r'F:\风控\A项目\单笔决策成本监控\模拟数据_1.xlsx')#读取数据
df['sql'] = df.apply(lambda x:f"""select *,'{x.列名}' as shujumingcheng from {x.表名} """,axis = 1) #建立新列
a = ''
for i in df['sql'].values:
a += i +'\n union all '
print(a) #进行sql拼接