【发布时间】:2015-08-05 18:54:26
【问题描述】:
以下是我的代码,
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 并且所有值都应该存储在数据框中。
谁能帮我做这件事?
【问题讨论】:
标签: python mysql python-2.7