我想在查询的SELECT语句(而不是WHERE语句)中使用LIKE或REGEX。
如果post_content包含'base64',我想在查询输出中看到1。有可能吗?
SELECT post_content, length(post_content), LIKE('%base64%') AS contained
FROM `wp_posts`
order by length(post_content) desc
答案 0 :(得分:3)
您可以使用Case语句
SELECT post_content, length(post_content),
(CASE WHEN post_content LIKE('%base64%') then "contained " ELSE "not contained" END) AS contained
FROM `wp_posts`
order by length(post_content) desc
OR
SELECT post_content, length(post_content),
post_content LIKE('%base64%') AS contained
FROM `wp_posts`
order by length(post_content) desc