Hello,
I have the following query, which is working fine, and returning correct result:
select COUNT (request_id) overdue
from requests
where submit_date > submit_date + 7;
But I need to place it into a report query as a subquery, and that's where I'm having problems:
select COUNT ( (select request_id
from requests
where SYSDATE > submit_date + 7))
overdue,
MAX (actual_resolution_date) last_completed,
COUNT (request_id) total_requests,
SUM (DECODE (status, 'Opened', 1, 0)) opened_requests,
SUM (DECODE (status, 'Completed', 1, 0)) completed_requests,
SUM (DECODE (status, 'Opened', DECODE (priority, 'High', 1, 0), 0)) high_prior
from requests
where country = :P11_country
I get an error - ORA-01427: single-row subquery returns more than one row
And if I change the COUNT subquery, like this:
select COUNT ( (select COUNT (request_id)
from requests
where SYSDATE > submit_date + 7))
overdue,
MAX (actual_resolution_date) last_completed,
COUNT (request_id) total_requests,
SUM (DECODE (status, 'Opened', 1, 0)) opened_requests,
SUM (DECODE (status, 'Completed', 1, 0)) completed_requests,
SUM (DECODE (status, 'Opened', DECODE (priority, 'High', 1, 0), 0)) high_prior
from requests
where country = :P11_country
Then I'm getting wrong results!
What could be a solution in this case, please?