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

前端之家收集整理的这篇文章主要介绍了sqlite:有没有办法在SELECT子句中创建条件OR / COALESCE?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下观点:

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,...
原文链接:https://www.f2er.com/sqlite/822979.html

猜你在找的Sqlite相关文章