我有以下观点:

CREATE VIEW FilmTableView AS

    SELECT  (TitleSP || " / " || TitleEN) as Title,
            CompanyName,
            CoverURI,
            CompanyFilmRelation.CompanyId,
            CompanyFilmRelation.FilmId

    FROM    Film
    JOIN    CompanyFilmRelation on CompanyFilmRelation.FilmId = Film.FilmId
    JOIN    Company on CompanyFilmRelation.CompanyId = Company.CompanyId

    ORDER BY Title;


但是我可能最终得到TitleSP或TitleEN为空的记录。在这种情况下,我只想包含不为null的任何列,并且不包含“ /”。

有没有办法做到这一点?也就是说,遵循以下逻辑:

if(TitleSP && TitleEN)
   select (TitleSP || " / " || TitleEN) as Title
else
   select (TitleSP ? TitleSP : TitleEn) as Title

最佳答案

SELECT CASE WHEN (TitleSP = '' OR TitleSP IS NULL)
                THEN COALESCE(TitleEN, '')
            WHEN (TitleEN = '' OR TitleEN IS NULL)
                THEN TitleSP
            ELSE (TitleSP || ' / ' || TitleEN)
       END AS Title,
...

10-06 13:27