在 MySQL 个案例运算符的结果上添加一些文本

Add some text on result of MySQL Case Operator

如何在 MySQL Case Operator 的结果上添加一些文本?

我想得到这样的结果:

<a href="/job/234/php-developer"></a>

我试过了,但语法错误:

SELECT (CASE
  WHEN job_url_outside IS NULL 
    THEN '<a href="/job/', job_id, '/', job_url, '"></a>' 
    ELSE '<a href="', job_url_outside, '" target="_blank" rel="noopener"></a>' 
    END) AS job_url 
  FROM job

尝试使用:

CONCAT(column,'some text',column)

更多信息here

你的情况是这样的:

SELECT (CASE
  WHEN job_url_outside IS NULL 
    THEN CONCAT('<a href="/job/', job_id, '/', job_url, '"></a>') 
    ELSE CONCAT('<a href="', job_url_outside, '" target="_blank" rel="noopener"></a>') 
    END) AS job_url 
  FROM job;

演示 here

您可能想要连接一些字符串?然后使用以下查询,其中添加了 CONCAT 以进行串联:

SELECT (CASE
  WHEN job_url_outside IS NULL 
    THEN CONCAT('<a href="/job/', job_id, '/', job_url, '"></a>') 
    ELSE CONCAT('<a href="', job_url_outside, '" target="_blank" rel="noopener"></a>') 
    END) AS job_url 
  FROM job

您应该将 href 字符串连接在一起。

SELECT (CASE WHEN job_url_outside IS NULL THEN '<a href="/job/' + job_id + '/' + job_url + '"></a>' ELSE '<a href="' + job_url_outside + '" target="_blank" rel="noopener"></a>' END) AS job_url FROM job