此代码使用sql-alchemy调用mysql表中的表
engine = create_engine("mysql+mysqldb://o:"+'o'+"@10.10.10.10/hukke"+"?charset=utf8mb4")
x="SELECT * FROM table1 Where "
data = pd.read_sql_query(x,con = engine)
print(data)
输出:
0 | 1
userid22 | sun
userid33 | mon
userid44 | earth
......
......
.....
表1有n行。例如,userid22有大约10 k行。就像那个3000用户id在表2中有100万行
如何调用第一个表的输出来获取第二个表中的值
表1返回了userid22,userid33,userid44等。所以取这三个值可以调用与表2中相关的行。
表1架构:
0 | 1
userid22 | sun
userid33 | mon
userid44 | earth
......
......
.....
表2架构:
0 | 1 | 2
userid22 | abc | acd
userid33 | bdc | axw
userid44 | earth | asd
......
......
.....
输出我需要:
使用表1中的前三个返回列。调用表2中的值。
好像你需要加入
select a.col0, a.col1, b.col1, b.col2
from tabl1 a
inner join b ona.col0 = b.col0
或者表1的前3个值
select a.col0, a.col1, b.col1, b.col2
from (
select col0
from table1
order by col0
limit 3
) t a
inner join b ona.col0 = b.col0