我有以下观点:
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,...