하위 쿼리에서 반환 된 총 결과 수를 얻으려고합니다. 나는이 작업을 수행하려면 어떻게PostgreSQL에서 하위 쿼리에서 반환 된 총 결과 수는 어떻게 얻습니까?
ERROR: relation "r" does not exist
LINE 3: ...on_id) as float)/(select count(*) as total from r) * 100.0...
^
********** Error **********
ERROR: relation "r" does not exist
SQL state: 42P01
Character: 112
: 나는 시도하고 이것을 실행할 때, 나는이 오류가, 그러나
select
count(r.reason_id) as num,
cast (count(r.reason_id) as float)/(select count(*) as total from r) * 100.0 as pct
from (
select
case
when rarreason != 0 then rarreason
else rejectreason end as reason_id
from
workorderlines
where
(rarreason != 0 or rejectreason != 0)
) as r
group by
r.reason_id
: 이것은 내 쿼리입니다? PostgreSQL 9.1을 사용하고 있습니다. 감사!
두 가지 제안이 모두 작동합니다. 감사합니다. –