[英]MySQL table left join not matching (MySQL, Python)
SOLVED see comments and solution 已解决,请参阅评论和解决方案
I have 2 scrapers which store there scraped data in 2 SQL tables: cpu and cpubench . 我有2个刮板,其中将刮板数据存储在2个SQL表中: cpu和cpubench 。
cpu contains : name, price, id(this is not constant across scrapers), mark cpu包含 :名称,价格,id(这在刮板中不是恒定的),标记
cpubench contains : name, mark, cpurank cpubench包含 :名称,标记,cpurank
Here is a snippet from these tables: 以下是这些表的摘录:
cpu 中央处理器
name price id mark AMD Ryzen 5 2600 $259.00 jLF48d 0 Intel Core i7-8700K $573.74 sxDzK8 0 AMD Ryzen 7 2700X $449.69 bddxFT 0 Intel Core i5-8600K $396.39 Mr2rxr 0 AMD Ryzen 3 2200G $145.00 RkJtt6 0 Intel Core i9-9900K $829.61 jHZFf7 0 AMD Ryzen 5 2600X $300.00 6mm323 0 Intel Core i5-9600K $419.00 28qhP6 0 Intel Core i7-9700K $659.00 WtyV3C 0 AMD Ryzen 5 1600 $232.61 mV98TW 0
cpubench cpubench
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
Note: 注意:
All columns in both tables are VARCHAR(255) . 两个表中的所有列都是VARCHAR(255) 。
Tables are not in this exact order with names lining up perfectly. 表名称的排列顺序不完全相同。
I am using the following python code: 我正在使用以下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)
Which runs without error. 哪个运行没有错误。
However all the mark values in cpu are null. 但是,cpu中的所有标记值均为空。
How can i troubleshoot/solve this problem? 如何解决/解决这个问题?
Any help would be greatly appreciated. 任何帮助将不胜感激。
Update 更新
I have created a working SQL fiddle: https://www.db-fiddle.com/f/sngju1uUBNMF56eVVTYu6H/3 我创建了一个有效的SQL提琴: https : //www.db-fiddle.com/f/sngju1uUBNMF56eVVTYu6H/3
I have tried the code from the fiddle in python with it running but all cpu.mark values being null. 我已经尝试从python小提琴中的代码开始运行,但是所有cpu.mark值都为null。
Thanks 谢谢
AS per comments, am binding the final solution here: 根据评论,在这里绑定最终解决方案:
update cpu
join cpubench on UPPER(TRIM(cpu.`"name"`)) = UPPER(TRIM(cpubench.`"name"`))
set cpu.`"mark"` = cpubench.`"mark"`;
SELECT * FROM cpu;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.