Mat*_*Mat 5 mysql sql database
我有一个包含域名的MySQL表:
+----+---------------+
| id | domain |
+----+---------------+
| 1 | amazon.com |
| 2 | google.com |
| 3 | microsoft.com |
| | ... |
+----+---------------+
Run Code Online (Sandbox Code Playgroud)
我希望能够在此表中搜索完整的主机名(即"www.google.com").如果它是相反的方式,表中包含我使用的完整URL:
SELECT * FROM table WHERE domain LIKE '%google.com%'
Run Code Online (Sandbox Code Playgroud)
但反过来并不那么简单.我目前的想法是搜索完整的主机名,然后逐步剥离域的每个部分,然后再次搜索.(即搜索'www.google.com'然后'google.com')
这不是特别有效或聪明,必须有更好的方法.我确信这是一个常见的问题,毫无疑问很容易解决!
Gre*_*reg 14
您也可以使用右侧的列:
SELECT domain FROM table WHERE 'www.google.com' LIKE CONCAT('%', domain);
Run Code Online (Sandbox Code Playgroud)
要么
SELECT domain FROM table WHERE 'www.google.com' LIKE CONCAT('%', domain, '%');
Run Code Online (Sandbox Code Playgroud)
它不是特别有效但它有效.
| 归档时间: |
|
| 查看次数: |
6096 次 |
| 最近记录: |