SELECT content_regex,content FROM mytable
WHERE content REGEXP 'Facebook|Dropbox|Microsoft'
AND created_date > DATE_ADD(NOW(),INTERVAL -1 day);
我使用REGEXP搜索内容。我想知道有没有办法知道哪个正则表达式值与内容匹配?
答案 0 :(得分:2)
使用CASE WHEN
:
SELECT content_regex,content
, CASE WHEN content LIKE 'Facebook' THEN 'Facebook'
WHEN content LIKE 'Dropbox' THEN 'Dropbox'
WHEN content LIKE 'Microsoft' THEN 'Microsoft'
END AS match
FROM mytable
WHERE content REGEXP 'Facebook|Dropbox|Microsoft'
AND created_date > DATE_ADD(NOW(),INTERVAL -1 day);