【问题标题】:how to insert sum of the columns in select query in postgresql?如何在postgresql的选择查询中插入列的总和?
【发布时间】:2017-02-07 19:50:58
【问题描述】:

我有一个选择查询,我的列类型是文本,然后我使用查询将其转换为整数

 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) 函数不存在。请帮忙!!!

【问题讨论】:

    标签: postgresql


    【解决方案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;
    

    【讨论】:

      猜你喜欢
      • 2013-04-03
      • 2013-11-30
      • 1970-01-01
      • 2014-09-01
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多