Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Need Help with another SQL query
On Fri, 17 Apr 1998 13:26:07 -0600, dwarakv_at_hotmail.com
wrote:
> I need to write a query which lists all the proj_id, and the difference in
>number of records with end_date > sysdate and end_date> (sysdate-7).
Something like this might work:
select proj_id, count_1 - count_2 from (select proj_id, count(*) count_1 from XXX where end_date > sysdate) XXX_1 (select proj_id, count(*) count_2 from XXX where end_date > sysdate+7) XXX_2 where XXX_1.proj_id = XXX_2.proj_id;
The query has two subselects. One returns the project IDs and the counts where end_date > sysdate. The other returns the same info for the case where end_date > sysate+7. I joined the two subqueries on project_id so that each row in the result set contains both counts.
Does this help?
Jonathan Received on Fri Apr 17 1998 - 21:50:57 CDT
![]() |
![]() |