SQL WHERE 字符串 LIKE 字段 [英] SQL WHERE string LIKE field
本文介绍了SQL WHERE 字符串 LIKE 字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格跟踪链接结构如下:
id域名交通计数启用created_at
假设我有一个 domain_name 为some-domain.com"的记录,然后假设我想找到具有该域的记录,除了我必须经过的是该域的子域.>
我本质上想这样做:
SELECT * FROM links 'subdomain.some-domain.com' LIKE %domain_name%"
我该怎么做?
解决方案
更新(感谢 Chad Johnson):
SELECT * FROM links WHERE 'subdomain.some-domain.com' LIKE CONCAT('%', domain_name, '%')
I have a table tracking links structured as follows:
id
domain_name
traffic_count
enabled
created_at
Let's say I have a record with domain_name of "some-domain.com", and then let's say I want to find the record having that domain, except all I have to go by is a subdomain of that domain.
I essentially want to do this:
SELECT * FROM links 'subdomain.some-domain.com' LIKE %domain_name%"
How would I do this?
解决方案
Updated (thanks to Chad Johnson):
SELECT * FROM links WHERE 'subdomain.some-domain.com' LIKE CONCAT('%', domain_name, '%')
这篇关于SQL WHERE 字符串 LIKE 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文