小编典典

sqlite:有没有办法在SELECT子句中产生条件OR / COALESCE?

sql

我有以下观点:

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

阅读 165

收藏
2021-04-28

共1个答案

小编典典

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, 
...
2021-04-28