MySQL table 左连接不匹配 (MySQL, Python)

MySQL table left join not matching (MySQL, Python)

已解决查看评论和解决方案

我有 2 个抓取器,它们将抓取的数据存储在 2 个 SQL 表中:cpucpubench .

cpu 包含: name, price, id(这在爬虫中不是常量),mark

cpubench contains: name, mark, cpurank

以下是这些表格的摘录:

cpu

name price id mark AMD Ryzen 5 2600 9.00 jLF48d 0 Intel Core i7-8700K 3.74 sxDzK8 0 AMD Ryzen 7 2700X 9.69 bddxFT 0 Intel Core i5-8600K 6.39 Mr2rxr 0 AMD Ryzen 3 2200G 5.00 RkJtt6 0 Intel Core i9-9900K 9.61 jHZFf7 0 AMD Ryzen 5 2600X 0.00 6mm323 0 Intel Core i5-9600K 9.00 28qhP6 0 Intel Core i7-9700K 9.00 WtyV3C 0 AMD Ryzen 5 1600 2.61 mV98TW 0

cpu长凳

name mark cpurank AMD Ryzen 5 2600 13527 160 Intel Core i7-8700K 15962 98 AMD Ryzen 7 2700X 16971 75 Intel Core i5-8600K 12786 175 AMD Ryzen 3 2200G 7325 503 Intel Core i9-9900K 20150 37 AMD Ryzen 5 2600X 14342 135 Intel Core i5-9600K 13498 162 Intel Core i7-9700K 17379 69 AMD Ryzen 5 1600 12264 187

注:

两个表中的所有列都是VARCHAR(255).

表格的顺序与名字排列不一致。

我正在使用以下 python 代码:

mycursor = mydb.cursor()

sql = ("SELECT cpu.id, cpu.name, cpu.price, cpubench.mark FROM cpu LEFT JOIN 
cpubench ON cpu.name = cpubench.name")

mycursor.execute(sql)

运行没有错误。

然而cpu中的所有标记值都是空的。

我怎么troubleshoot/solve这个问题?

如有任何帮助,我们将不胜感激。

更新

我创建了一个工作 SQL fiddle: https://www.db-fiddle.com/f/sngju1uUBNMF56eVVTYu6H/3

我已经尝试使用 python 中的 fiddle 中的代码 运行 但所有 cpu.mark 值都为空。

谢谢

根据评论,我在这里绑定最终解决方案:

update cpu 
join cpubench on UPPER(TRIM(cpu.`"name"`)) = UPPER(TRIM(cpubench.`"name"`)) 
set cpu.`"mark"` = cpubench.`"mark"`;

SELECT * FROM cpu;