Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

COUNT subquery

690972Mar 3 2011 — edited Mar 3 2011
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?
This post has been answered by 731104 on Mar 3 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2011
Added on Mar 3 2011
2 comments
521 views