Skip to Main Content

SQL & PL/SQL

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!

using the inner query to filter outer query

648695Jul 8 2008 — edited Jul 8 2008
hi

i've tried finding an old post on this, but there's nothing quite what im looking for. I have an inner query which gets sales totals, and an outer query with an outer join to return all the weeks (even when there are no sales):-
-----------------------------------------------------------------------------------
select wk.week_id,sum(sales_total)
from (select week, sum(sales) sales_total from tbl_sales_A
where week between 0801 and 0807
group by week
UNION ALL
select week, sum(sales) sales_total from tbl_sales_B
where week between 0801 and 0807
group by week)
, tbl_weeks wk
WHERE
wk.week_id=week(+)
AND wk.week_id BETWEEN 0801 AND 0807
GROUP BY wk.week_id
-----------------------------------------------------------------------------
this gives me the following results:-
week_id sales
0801 0
0802 0
0803 55
0804 66
0805 96
0806 0
0807 97
-----------------------------------------------------------------------------
I would like my query to only return results from the first week sales are made i.e. 0803. The results would like this:-
---------------------------------------------------------------------------
0803 55
0804 66
0805 96
0806 0
0807 97
----------------------------------------------------------------------------
How do i write my query so that it does this???

Many thanks for your time.

Message was edited by:
user645692
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2008
Added on Jul 8 2008
6 comments
616 views