以下是我的代码,
connect=Tl.connection.Connection()
a= connnect.connect('dbname', schema='schemaname')
q='''select id, id1 from table1;'''
w= Tl.datatool.todf(a(q))
id=w.id
id1=w.id1
现在对于每个 id 和 id1,我需要执行第二个查询,它应该像一个循环并且应该存储在数据帧中,
我正在寻找的查询是,
select id2 from table2 where x=id and y=id1;
我正在努力
for i in id:
for j in id1:
q2='''select id2 from table2 where x=%i and y=%i;''' (int(id), int(id1))
print a(q2)
但我无法获得确切的输出。我收到以下错误,
TypeError: 'str' object is not callable
我正在寻找的输出是,对于 id 和 id1 的所有值,我需要获取 id2 并且所有值都应存储在数据框中。
有人可以帮我做这件事吗?
最佳答案
您忘记使用%
运算符:
q2='''select id2 from table2 where x=%i and y=%i;''' (int(id), int(id1))
应该阅读
q2='''select id2 from table2 where x=%i and y=%i;''' %(int(id), int(id1))
关于python - 使用一个查询的输出输入另一个查询 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31840609/