假设这是我需要的查询:
SELECT * FROM `products` WHERE `keywords` LIKE "%(SELECT `key` FROM `keywords` WHERE `slug` = '%d8%af%db%8c%d9%88%d8%a7%d8%b1' LIMIT 1)%"
目前它不起作用并且在满足条件的记录时返回零结果 我想知道这里有什么问题?
答案 0 :(得分:6)
这应该有效:
SELECT *
FROM products
WHERE keywords LIKE
CONCAT('%', (SELECT `key` FROM `keywords`
WHERE `slug` = '%d8%af%db%8c%d9%88%d8%a7%d8%b1' LIMIT 1), '%');
答案 1 :(得分:1)
尝试这个,不确定它是否会起作用......
SELECT * FROM products
WHERE keywords LIKE "%" + (SELECT key FROM keywords WHERE slug = 'something' LIMIT 1) + "%";
答案 2 :(得分:1)
另一个带有like和嵌套SELECT的工作示例:
SELECT COUNT(email) as count FROM table1 t1
JOIN (
SELECT company_domains as emailext FROM table2 WHERE company = 'DELL'
) t2
ON t1.email LIKE CONCAT('%', emailext) WHERE t1.event='PC Global Conference";
如果电子邮件扩展名等于多个公司域,则任务是使用过滤器对事件进行计数。如果有人觉得这很有用