0

CONCAT_WS を使用して件名を生成しようとしています。ただし、値がnullの場合はセパレーターを無視したいです。

このクエリを見てください

SELECT
CONCAT_WS(" ",
CASE WHEN total_attempts > 0 THEN
CONCAT( call_code_title , " - ", total_attempts, "<sup>",
    CASE WHEN total_attempts = 2 THEN "nd"
    WHEN total_attempts = 3 THEN "rd"
    ELSE "th" END
, "</sup> attempt") ELSE call_code_title END
, "-", program_name) AS callSubject
FROM table

問題は、「program_name」が NULL の場合、文字列の最後に常に「-」が付くことです。"-" id program_name IS NULL を連結したくない

それ、どうやったら出来るの?

ありがとう

4

2 に答える 2

0

IFNULL(プログラム名, concat("-", プログラム名))

SELECT
CONCAT_WS(" ",
CASE WHEN total_attempts > 0 THEN
CONCAT( call_code_title , " - ", total_attempts, "<sup>",
    CASE WHEN total_attempts = 2 THEN "nd"
    WHEN total_attempts = 3 THEN "rd"
    ELSE "th" END
, "</sup> attempt") ELSE call_code_title END
, IFNULL(program_name, concat("-", program_name)) , " " ) AS callSubject
FROM table
于 2013-09-18T02:12:03.310 に答える