我想用language_id' us'来显示已翻译的名称和说明。和' ru。我的问题是如何删除空值?
SELECT DISTINCT CASE WHEN LANGUAGE_ID = 'US' THEN COALESCE(TO_CHAR(TRANSLATED_NAME), ' ')
END AS PRODUCT_NAME_US,
CASE WHEN LANGUAGE_ID = 'US' THEN INITCAP(CONCAT(SUBSTR(TRANSLATED_DESCRIPTION, 1, 30), '...'))
END AS PRODUCT_DESC_US,
CASE WHEN LANGUAGE_ID = 'RU' THEN COALESCE(TO_CHAR(TRANSLATED_NAME), ' ')
END AS PRODUCT_NAME_RU,
CASE WHEN LANGUAGE_ID = 'RU' THEN INITCAP(CONCAT(SUBSTR(TRANSLATED_DESCRIPTION, 1, 30), '...'))
END AS PRODUCT_DESC_RU
FROM PRODUCT_DESCRIPTIONS;
答案 0 :(得分:1)
我怀疑你想要这样的东西:
SELECT PRODUCT_ID,
MAX(CASE WHEN LANGUAGE_ID = 'US' THEN COALESCE(TO_CHAR(TRANSLATED_NAME), ' ')
END) AS PRODUCT_NAME_US,
MAX(CASE WHEN LANGUAGE_ID = 'US' THEN INITCAP(CONCAT(SUBSTR(TRANSLATED_DESCRIPTION, 1, 30), '...'))
END) AS PRODUCT_DESC_US,
MAX(CASE WHEN LANGUAGE_ID = 'RU' THEN COALESCE(TO_CHAR(TRANSLATED_NAME), ' ')
END) AS PRODUCT_NAME_RU,
MAX(CASE WHEN LANGUAGE_ID = 'RU' THEN INITCAP(CONCAT(SUBSTR(TRANSLATED_DESCRIPTION, 1, 30), '...'))
END) AS PRODUCT_DESC_RU
FROM PRODUCT_DESCRIPTIONS
GROUP BY PRODUCT_ID; -- whatever each row defines
这为每个产品做了明确的聚合(当然使用适当的id),将英语和俄语翻译放在适当的列中。