当前位置:   article > 正文

pg的with查询结合COALESCE将未查询到记录的内容默认置零_pgsql如何用case when表示没查到数据时

pgsql如何用case when表示没查到数据时

pg的with查询结合COALESCE将未查询到记录的内容默认置零

with t as (
    select ('CNY') union select ('USD')union select ('EUR') union select ('JPY') union select ('HKD') 
)
select t."?column?" as currency,case when amount is null then 0 else amount end as amount
from t left join today_pay_amount p on t."?column?" = p.currency 

with t as (
    select ('CNY') union select ('USD')union select ('EUR') union select ('JPY') union select ('HKD') 
)
select t."?column?" as currency,COALESCE(p.amount, 0) as amount
from t left join today_pay_amount p on t."?column?" = p.currency 

简单结果可以用 SELECT 
    decode(count(amount), 1, SUM(amount), 0)
FROM B 解决

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/974644
推荐阅读
相关标签
  

闽ICP备14008679号