你能告诉我如何在postgre中使用CASE和IFNULL吗?我正在从sql迁移到postgreSQL,我想用这种语法创建一个函数:
SELECT a.furniture_id, a.furniture_brand, a.furniture_cost,
CASE
WHEN furniture_id = f_id THEN a.furniture_content
ELSE ''
END CONTENT
FROM tb_furniture a
WHERE
(IFNULL(a.sale_id,0) = IFNULL(f_id,0) OR (a.furniture_id = f_Id AND IFNULL(a.furniture_content,'') > ''))
AND a.published = 1;
感谢之前(y)
答案 0 :(得分:3)
这似乎就是你所追求的,但请仔细检查WHERE
条件:
SELECT a.furniture_id, a.furniture_brand, a.furniture_cost,
CASE WHEN a.furniture_id = f_id
THEN a.furniture_content
ELSE ''
END AS content
FROM tb_furniture a
WHERE (coalesce(a.sale_id,0) = coalesce(f_id,0) OR length(content) > 0)
AND a.published = 1;