我可以在里面做一个吗? 或者只有在字段不为null(path = null)时才允许我进行检查的东西
SELECT
IF(path IS NOT NULL, concat("/uploads/attachments/",path, "/thumbnails/" , nome), "/uploads/attachments/default/thumbnails/avatar.png") as avatar_mittente
FROM prof_foto
WHERE profilo_id = 15
-- only if path != "/uploads/attachments/default/thumbnails/avatar.png"
AND foto_eliminata = 0 AND foto_profilo = 1
答案 0 :(得分:1)
你可以试试这个
SELECT
IF(path IS NOT NULL, concat("/uploads/attachments/",path, "/thumbnails/" , nome), "/uploads/attachments/default/thumbnails/avatar.png") as avatar_mittente
FROM prof_foto
WHERE profilo_id = 15
AND IF( path != "/uploads/attachments/default/thumbnails/avatar.png",
foto_eliminata = 0 AND foto_profilo = 1,
foto_eliminata like '%' AND foto_profilo like '%'
)
答案 1 :(得分:0)
您可以使用二进制逻辑:
SELECT * FROM TABLE WHERE A
(if b then also where C)
变为
SELECT * FROM TABLE WHERE A
AND (!b OR C)
在你的情况下:
SELECT
IF(path IS NOT NULL, concat("/uploads/attachments/",path, "/thumbnails/" , nome), "/uploads/attachments/default/thumbnails/avatar.png") as avatar_mittente
FROM prof_foto
WHERE profilo_id = 15
AND (path = "/uploads/attachments/default/thumbnails/avatar.png" OR foto_eliminata = 0 AND foto_profilo = 1))
答案 2 :(得分:0)
是的,您可以在预期值的任何地方使用IF()
,即使大部分时间它都不是最佳路线。
WHERE IF(path IS NULL, portfolio_id = 15, TRUE)
但更喜欢:
WHERE path IS NULL OR portfolio_id = 15
(请注意,您无法与NULL
进行比较,[anything] = NULL
始终为FALSE
)