【问题标题】:How to call postgreSQL count如何调用 postgreSQL 计数
【发布时间】:2016-02-02 09:13:14
【问题描述】:

如何在程序上调用 postgreSQL 计数值,因为 select count 是显示值,但在我的程序代码中只使用计数显示错误

select
    --poui.id::varchar || '/' || coalesce(poc.id::varchar,'') AS id,
    poui.preorder_id as name,
    poc.start_date as start_date,
    poc.expire_date as end_date,
    poui.state as status,
    select count(*) as no_preorder_completed from preorder_user_input where state = 'done'
    select count(*) as no_preorder_not_completed from preorder_user_input where state in ('draft','confirm')
    count(*) as no_preorder_completed from preorder_user_input where state = 'done'

from
    preorder_user_input poui
left join 
    preorder_config poc on (poui.preorder_id = poc.id)
group by 
    poc.id, poui.id, poui.preorder_id, poc.expire_date, poc.start_date, poui.state

【问题讨论】:

    标签: python-2.7 postgresql-9.1


    【解决方案1】:

    通常,如果您想对 PostgreSQL 9.1 中的某些行进行计数,则需要使用 SUM 和 CASE。即

    SUM(CASE WHEN mycolumn = desired THEN 1 ELSE 0 END)
    

    【讨论】:

      猜你喜欢
      • 2010-12-29
      • 2010-11-27
      • 2012-09-30
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 2015-03-25
      相关资源
      最近更新 更多