1

SELECTインスタンスの数をカウントして変数に保存するステートメントがあります。aと aを行うHAVING節があります。ただし、havingを使用するには a が必要なため、selectステートメントは、合計が 4 ではなく、1 である 4 行を返します。これにより、変数にカウントが 4 として保存されず、1 として保存されます。必要なので、代替の回避策を探しています。SUMCOUNTGROUP BY

    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;
4

1 に答える 1

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;
于 2013-11-04T19:02:35.310 に答える