“拥有”的替代品

时间:2013-11-04 18:48:46

标签: sql pervasive-sql

我有一个SELECT语句,它计算实例数,然后保存在变量中。它有一个HAVING子句,可以执行SUMCOUNT。但是,由于您必须拥有GROUP BY才能使用 select 语句将返回4行而不是总数为4的行。不会将计数保存为变量为4但是为1显然不是我需要的,所以我正在寻找替代方法。

    select count(distinct p1.community) 
        from
            "Database".prospect p1
    where 
        p1.visit_date >= '2013-07-01' 
        and p1.visit_date <= '2013-09-30'
        and p1.division = '61'  
    group By 
        p1.community
    having 
        sum(p1.status_1) / count(p1.control_code) >= .16;

1 个答案:

答案 0 :(得分:1)

这是一个合理的选择:

select count(*)
from (
select p1.community , sum(p1.status_1) / count(p1.control_code) SomeColumn
        from
            "Database".prospect p1
    where 
        p1.visit_date >= '2013-07-01' 
        and p1.visit_date <= '2013-09-30'
        and p1.division = '61'  
    Group By 
        p1.community
) A
where A.SomeColumn >= .16;