如何在postgresql中的select查询中插入列的总和?

时间:2017-02-07 19:50:58

标签: postgresql

我有一个选择查询,我的列类型是文本,但我输入后使用查询

键入它
 select case
   when fti.status!='not signed' then  1::integer
   when ftrq.is_the_site_cleared = '1' then 1::integer 
   when ftrq.is_the_site_cleared = '0' then 0::integer
   end as is_the_site_cleared from fti join ftrq on ftrq.fulcrum_parent_id = fti.fulcrum_id

我确实有这样的列数,并希望将它们的总数作为列中的最后一个值,可能就像底部的sum(is_the_site_cleared)。我怎样才能做到这一点?我正在使用postgresql 9.3,它说sum(text)函数不存在。请帮忙!!!

1 个答案:

答案 0 :(得分:1)

    select sum(is_the_site_cleared) from (select case
       when fti.status!='not signed' then  1
       when ftrq.is_the_site_cleared = '1' then 1 
       when ftrq.is_the_site_cleared = '0' then 0
       end as is_the_site_cleared from fti join ftrq on 
       ftrq.fulcrum_parent_id = fti.fulcrum_id) res;
相关问题