Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> How to return a record of 0 for sums of time periods where there was no record.
Hi,
Back in september I posted for help with an odd query; the challenge was to return a monthly summation which includes a zero value for months during which there is no record at all.
ie. not this...
01/11/2002 20010 15003 01/01/2003 100000 50000 01/03/2003 500000 250000 01/04/2003 200000 100000 573000 277830
but this...
01/11/2002 20010 15003 01/12/2002 0 0 01/01/2003 100000 50000 01/02/2003 0 0 01/03/2003 500000 250000 01/04/2003 200000 100000 573000 277830
The original thread is here...
but I can't add to that thread no more... so here's a new one.
I never posted a final solution, and here I am just a couple of months later having to solve it again (in a different workplace). Thus, so that I don't need to nut it out a third time, I now post a working solution.
select trunc(month,'month') as month,
sum(contract_value) as contract_value, sum(win_value) as win_value
union
Notes:
That undated last row is a sum of all records with null in
opp_fall_date. This example sums the upcoming 6 months. You should
probably change "all_tab_columns" to some other minor table for
efficiency's sake, and all credit remains with Candido Dessanti.
thanks,
john.
Received on Wed Nov 27 2002 - 18:08:46 CST