當我從資料庫回傳我的影像時,我試圖添加指向我的影像的鏈接,但是當影像為空時我不想添加它。我試過了CONCAT,CONCAT_WS但沒有用
這兩個都不起作用:
SELECT id, name_en as name, CONCAT_WS("http://website.com/", image) as image FROM businesses
SELECT id, name_en as name, CONCAT("http://website.com/", image) as image FROM businesses
uj5u.com熱心網友回復:
您可以使用ìFflowcoltrol,`來確定 iif 影像是否為 NULL,如果不是則添加 url
SELECT id, name_en as name, IF(image IS NOT NULL, CONCAT("http://website.com/", image),"") as image
FROM businesses
uj5u.com熱心網友回復:
您正在尋找的是 COALESCE() 函式:下面的檔案鏈接。它回傳系列中的第一個非空值。所以本質上我們用空字串替換 Null 。
SELECT id, name_en as name, CONCAT("http://website.com/", coalesce(image,'')) as image
FROM businesses
https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#function_coalesce
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/383197.html
