![](/img/trans.png)
[英]How to map rows of two tables to each other based on the relevance in MySQL?
[英]How to match part of rows in different tables with each other in MySQL?
我有一個名為“ urls”的表,其中包含不同國家的域名,如下所示:
Domain
Paypal.com
wellsfargo.co.uk
sparkasse.fe.de
等等...
我還有另一個名為“國家”的表,其中包含tlds及其相關國家,如下所示:
tld country
nl netherlands
de germany
uk united kingdom
etc...
我不知道如何創建一個匹配項,以便能夠從“ URL”表中的域中提取“ country”表中的國家/地區名稱。有人可以幫助我嗎?
使用以下JOIN
條件聯接兩個表:
ON ( country.tld = RIGHT(urls.domain, CHAR_LENGTH(tld)) )
請注意,如果存在這樣的索引,則該查詢無法在urls.domain
使用索引。 我將在插入單獨的列(在urls
)時預先計算urls.domain
的頂級域。 在此新列上設置索引,並在您的JOIN
條件下使用此列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.