【发布时间】:2021-03-21 12:42:28
【问题描述】:
我想获取单元格值以传递给 SQL 查询中的 where 条件。下面一个是我的数据框ab。数据框只有不同的值
+----------+--------+
|Months | YEAR|
+----------+--------+
| 3| 2018|
| 2| 2014|
+----------+--------+
基于这些我需要将值传递给 SQL 查询
for i in range(0,ab.count()):
query = "select * from customer where YEAR= "+ab['YEAR'][i]+" and Months="+ab['Months'][i]
df = sqlContext.read.format("jdbc").options(url="jdbc:mysql://localhost:3306/ohcdemo",driver="com.mysql.jdbc.Driver",query=query,user="root",password="root").load()
它应该通过编写 SQL 查询无法获取 SQL 查询的值来附加到数据帧
【问题讨论】:
标签: mysql sql python-3.x apache-spark pyspark