Need help getting YTD total

I've got a period to date report with following columns:
week1 tots, week2 tots, week3 tots, week4 tots, week5 tot, period-to-date tots, year-to-date tots
I have a SELECT statement which totals data for the entire year and separates current period totals
by grouping on the week_nbr . Any date between beginning of year and the end of the previous period will be week 0
The Select statement retursn 6 rows: 1 for each week in period and one with week_nbr = 0 which represents the totals from the beginning of year
to the end of the previous period.
the select statement returns the data correctly . I need help getting the YTD total for (weeks 1 - 5) + (totals for week 0) for each column.
This means that I will have a 7th record containing the YTD totals. ( I am not concerned with the PTD totals)
I tried sum by partition but complex decode statement gave me problems.
  CREATE TABLE PERIOD_DATA
   (     "HOT_DOG_STAND_ID" NUMBER NOT NULL ENABLE,
     "WEEK_DATE" DATE,
     "NET_SALES2" NUMBER,
     "BUNS24434" NUMBER,
     "PICKELS_AW38" NUMBER,
     "MUSTARD_TB56" NUMBER,
     "CHICKENHEADS33" NUMBER,
     "PIECES_SOLD34" NUMBER,
     "SCRAPS35" NUMBER,
     "PIECES_UNACCOUNTED" NUMBER
REM INSERTING into PERIOD_DATA
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('29-DEC-08','DD-MON-RR HH.MI.SSXFF AM'),14301.39,13951.26,3431.13,0,3680,2484,378,818);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('05-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),14651.37,14651.37,3249.55,0,3200,2419,505,276);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('12-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),14169.89,14169.89,2463.53,0,3136,2080,474,582);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('19-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),15864.46,15864.46,3245.49,0,3472,2764,475,233);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('26-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),15961.2,15916.23,3395.51,0,3648,2838,392,418);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('02-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),19066.4,19066.4,4165.07,0,4336,3682,333,321);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('09-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),18415.74,18415.74,4024.74,0,4032,3365,482,185);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('16-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),18014,17849,3486.33,0,3840,3238,374,228);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('23-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),18671.09,18626.12,3729.42,0,3888,2970,353,565);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('02-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),17636,17636,3815,0,3424,2840,490,94);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('09-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),17235.52,17145.58,3897.42,0,3504,2928,421,155);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('16-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),15989.27,15989.27,3372.95,0,3728,3051,369,308);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('23-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),19067.69,18960.41,4152.6,0,4048,3293,442,313);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('30-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),18717.99,18717.99,3923.69,0,4408,3219,593,596);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('06-APR-09','DD-MON-RR HH.MI.SSXFF AM'),17335.16,17335.16,3769.08,0,3928,2997,514,417);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('13-APR-09','DD-MON-RR HH.MI.SSXFF AM'),18967.39,18967.39,4157.76,0,4144,2991,527,626);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('20-APR-09','DD-MON-RR HH.MI.SSXFF AM'),23090.88,23090.88,4427.96,0,5544,4493,560,491);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('27-APR-09','DD-MON-RR HH.MI.SSXFF AM'),24197.98,24132.99,4248.66,0,6680,5190,606,884);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('04-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),20202.21,20137.22,3714.68,0,7052,6170,422,460);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('11-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),18514.48,18514.48,3266.06,0,5508,4178,571,759);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('18-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),18678.68,18678.68,3814.07,0,5824,4345,633,846);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('25-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),17937.18,17937.18,3051.52,0,4844,4986,529,-671);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('01-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),17445.75,17445.75,3079.91,0,5028,4810,656,-438);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('08-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),17327.88,17327.88,3263.29,0,6112,4674,672,766);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('15-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),17241.72,16937.33,3328.27,0,5792,4490,567,735);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('22-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),16625.83,16625.83,3485.18,0,5408,4319,761,328);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('29-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),17002.84,17002.84,3091.09,0,5664,4369,544,751);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('06-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),16339.19,16274.2,3075.3,0,4784,3440,697,647);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('13-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),17165.12,16885.14,3458.03,0,4320,3296,640,384);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('20-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),17029.77,16899.79,3198.91,0,4448,3449,645,354);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('27-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),16596.89,16596.89,3015.54,0,4624,3288,665,671);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('03-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),16468.58,16468.58,2981.35,0,2224,3495,564,-1835);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('10-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),18625.48,18550.5,3524.44,0,4856,3482,578,796);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('17-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),24538.54,24323.55,5580.71,0,5260,3771,608,881);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('24-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),18081.37,18081.37,3533.45,0,5980,3080,553,2347);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('31-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),17183.25,17183.25,3487.12,0,2544,3262,615,-1333);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('07-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),17688.41,17575.29,3424.17,0,4800,3480,591,729);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('14-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),18211.29,18211.29,3806.32,0,3968,3104,527,337);
Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('21-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),16809.21,16744.22,3014.61,0,4128,3124,710,294);
SELECT HOT_DOG_STAND_ID
, DECODE(TRUNC(week_date , 'iw') ,
         to_date('24-AUG-09' , 'dd-mon-rr') , 1 ,
         to_date('24-AUG-09' , 'dd-mon-rr') + 7 , 2 ,
         to_date('24-AUG-09' , 'dd-mon-rr') + 14 , 3 ,
         to_date('24-AUG-09' , 'dd-mon-rr') + 21 , 4 ,
         to_date('24-AUG-09' , 'dd-mon-rr') + 28 , 5 , 0) AS week_nbr
, SUM(NET_SALES2)                                                                                                                                                                                                                                                     AS net_sales2
, SUM(BUNS24434 ) BUNS24434
, SUM(PICKELS_AW38) PICKELS_AW38
, SUM(MUSTARD_TB56) MUSTARD_TB56
, SUM(CHICKENHEADS33) CHICKENHEADS33
, SUM(PIECES_SOLD34) PIECES_SOLD34
, SUM(SCRAPS35) SCRAPS35
, SUM(PIECES_UNACCOUNTED) * - 1 PIECES_UNACCOUNTED
   /*--== Head average  net_sales / chickenusage*/
, CASE
      WHEN NVL( SUM(ChickenHeads33) / 8 , 0) = 0 THEN 0
      ELSE ROUND(SUM(net_sales2) / ( SUM(ChickenHeads33) / 8 ) , 2)
   END AS Head_average
   /*--=== Efficiency =   (ChickenUsage  - scrappedDiv8 - unaccountedDiv8) / ChickenUsage)  * 100*/
, CASE
      WHEN NVL(SUM(ChickenHeads33) / 8 , 0) = 0 THEN 0
      ELSE ROUND((((SUM(ChickenHeads33) / 8 ) - ( SUM(scraps35) / 8 ) - (SUM(pieces_unaccounted) / 8 )) / (SUM(ChickenHeads33) / 8 )) * 100 , 2)
   END AS efficiency
FROM period_data per
WHERE week_DATE BETWEEN TRUNC(TO_DATE( '24-AUG-09' , 'DD-MON-YY') , 'IY') AND TRUNC(TO_DATE( '24-AUG-09' , 'DD-MON-YY') , 'IW') + 6 + 7 * 4
GROUP BY hot_dog_stand_id
, DECODE(TRUNC(week_date , 'iw') ,
      to_date('24-AUG-09' , 'dd-mon-rr') , 1 ,
      to_date('24-AUG-09' , 'dd-mon-rr') + 7 , 2 ,
      to_date('24-AUG-09' , 'dd-mon-rr') + 14 , 3 ,
      to_date('24-AUG-09' , 'dd-mon-rr') + 21 , 4 ,
      to_date('24-AUG-09' , 'dd-mon-rr') + 28 , 5 ,
      0)
ORDER BY DECODE(TRUNC(week_date , 'iw') , to_date('24-AUG-09' , 'dd-mon-rr') , 1 , to_date('24-AUG-09' , 'dd-mon-rr') + 7 , 2 , to_date('24-AUG-09' , 'dd-mon-rr') + 14 , 3 , to_date('24-AUG-09' , 'dd-mon-rr') + 21 , 4 , to_date('24-AUG-09' , 'dd-mon-rr') + 28 , 5 , 0);The expected results will be:
HOT_DOG_STAND_ID       WEEK_NBR               NET_SALES2             BUNS24434              PICKELS_AW38           MUSTARD_TB56           CHICKENHEADS33         PIECES_SOLD34          SCRAPS35               PIECES_UNACCOUNTED     HEAD_AVERAGE           EFFICIENCY            
141                    7                      697067.09              694887.4               139149.91              0                      175808                 139454                 21036                  15318                  31.72                  79.32                  You can get these dame results by running endpot-to-endpoint query:
SELECT  HOT_DOG_STAND_ID
     , max(7) as week_nbr
     ,sum(NET_SALES2)      net_sales2
      ,sum(BUNS24434 )        BUNS24434
      ,sum(PICKELS_AW38)      PICKELS_AW38
      ,sum(MUSTARD_TB56)     MUSTARD_TB56
      ,sum(CHICKENHEADS33)   CHICKENHEADS33
      ,sum(PIECES_SOLD34)    PIECES_SOLD34
      ,sum(SCRAPS35)         SCRAPS35
      ,sum(PIECES_UNACCOUNTED)   PIECES_UNACCOUNTED
    ---===== Copied code from outer query
          --==  net_sales / chickenusage 
                  ,   CASE
                         WHEN NVL( sum(ChickenHeads33) / 8    ,0)  = 0 then 0
                         ELSE ROUND(sum(net_sales2)/   ( sum(ChickenHeads33) / 8    ) , 2)
                      END as Head_average
                    --=== Efficiency =   (ChickenUsage  - scrappedDiv8 - unaccountedDiv8) / ChickenUsage)  * 100
                    ,   CASE
                              WHEN NVL(sum(ChickenHeads33) / 8    ,0)  = 0 then 0
                              ELSE   ROUND((((sum(ChickenHeads33) / 8 )  - ( sum(scraps35) / 8 ) - (sum(pieces_unaccounted) / 8 )) / (sum(ChickenHeads33) / 8 )) * 100, 2)
                      END as efficiency  
from period_data
WHERE week_DATE BETWEEN TRUNC(TO_DATE( '24-AUG-09' ,'DD-MON-YY'), 'IY') AND TO_DATE( '27-sep-09' ,'DD-MON-YY')
group by hot_dog_stand_id;Thanks In Advance

Hi,
Welcome to the forum!
Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful. You could teach something to some people who have been using this forum for years (except that nobody can teach them).
user12335325 wrote:
The expected results will be:
HOT_DOG_STAND_ID       WEEK_NBR               NET_SALES2             BUNS24434              PICKELS_AW38           MUSTARD_TB56           CHICKENHEADS33         PIECES_SOLD34          SCRAPS35               PIECES_UNACCOUNTED     HEAD_AVERAGE           EFFICIENCY            
141                    7                      697067.09              694887.4               139149.91              0                      175808                 139454                 21036                  15318                  31.72                  79.32                 
Do you mean the expected results will include the row above, and that the results will be this row along with the 6 rows you're already getting? (If you wanted just that one row, I suppose you would just run your second query.)
That sound like a job for ROLLUP.
VARIABLE   start_date     VARCHAR2 (11);
EXEC         :start_date  := '24-AUG-2009';
     SELECT  HOT_DOG_STAND_ID
     ,      NVL (CASE
               WHEN  week_date >= TO_DATE( :start_date, 'DD-MON-YYYY')
               AND   week_date <  TO_DATE( :start_date, 'DD-MON-YYYY') + 35
               THEN  1 + FLOOR ( (week_date - TO_DATE( :start_date, 'DD-MON-YYYY'))
                                         / 7
               ELSE  0
                  END
             , 7
             )          AS week_nbr
, SUM(NET_SALES2)                                                                                                                                                                                                                                                     AS net_sales2
, SUM(BUNS24434 ) BUNS24434
, SUM(PICKELS_AW38) PICKELS_AW38
, SUM(MUSTARD_TB56) MUSTARD_TB56
, SUM(CHICKENHEADS33) CHICKENHEADS33
, SUM(PIECES_SOLD34) PIECES_SOLD34
, SUM(SCRAPS35) SCRAPS35
, SUM(PIECES_UNACCOUNTED) * - 1 PIECES_UNACCOUNTED
   /*--== Head average  net_sales / chickenusage*/
, CASE
      WHEN NVL( SUM(ChickenHeads33) / 8 , 0) = 0 THEN 0
      ELSE ROUND(SUM(net_sales2) / ( SUM(ChickenHeads33) / 8 ) , 2)
   END AS Head_average
   /*--=== Efficiency =   (ChickenUsage  - scrappedDiv8 - unaccountedDiv8) / ChickenUsage)  * 100*/
, CASE
      WHEN NVL(SUM(ChickenHeads33) / 8 , 0) = 0 THEN 0
      ELSE ROUND((((SUM(ChickenHeads33) / 8 ) - ( SUM(scraps35) / 8 ) - (SUM(pieces_unaccounted) / 8 )) / (SUM(ChickenHeads33) / 8 )) * 100 , 2)
   END AS efficiency
FROM period_data per
WHERE week_DATE BETWEEN TRUNC(TO_DATE( '24-AUG-09' , 'DD-MON-YY') , 'IY') AND TRUNC(TO_DATE( '24-AUG-09' , 'DD-MON-YY') , 'IW') + 6 + 7 * 4
GROUP BY  hot_dog_stand_id
,           ROLLUP (
             CASE
               WHEN  week_date >= TO_DATE( :start_date, 'DD-MON-YYYY')
               AND   week_date <  TO_DATE( :start_date, 'DD-MON-YYYY') + 35
               THEN  1 + FLOOR ( (week_date - TO_DATE( :start_date, 'DD-MON-YYYY'))
                                         / 7
               ELSE  0
             END          -- week_nbr
ORDER BY  week_nbr
;Notice I simplified the computation of week_nbr.
Some other people have asked questions about hot dog stands recently.
I'm curious; is this from a course? If so, where? What is the textbook (if any)?
Thanks.

Similar Messages

  • TS1538 i need help because i need help getting my ipod touch to connect to windows vista and

    i need help getting my ipod touch to connect to windows because it keeps saying udb device not recognized and i tr\]ied restarting the settings!!!!!

    Have you tried here:
    iOS: Device not recognized in iTunes for Windows

  • I need help getting itunes on my new computer. old one crashed

    My old computer crashed, I downloaded iTunes on my new computer and need help getting all of my stuff on it that I had. I did 'home share' to see if that worked, and it didnt.
    Also, on my old computer, when I synced my iPad & my husbands iPod, it didnt sync any music or podcasts, no videos-and i went through each category seperately to sync it and it didnt work. So I can't sync my devices to the new iTunes bc not everything is on there that i have purchased.

    It has always been very basic to always maintain a backup copy of your comuter for just this occasion.  Use your backup copy to put everything on the new computer.
    If for some reason you have failed to maintain a backup, not good, then you can redownload some itunes purchases in some countries:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • TS4268 I need help getting my face time and imessage to work.

    I need help getting my face time and imessage to work. It is saying wating for activation. I just got my iphone 5 2 days ago. I have reset it from the phone and from itunes on the computer, made sure I'm attached to wifi.

    The 3 basic troubleshooting steps are these in order: 1. Restart your iphone  2.  Reset your settings/iphone  3.  Restore your iphone.  Since your iphone is only a couple of days old, you should backup your device before restoring.  If you don't have anything on your iphone that you care to lose, then simply restoring without a backup is fine.  A quick reset of pressing the sleep/wake button (top of iphone) and your home button simultaneously and holding it until the silver Apple logo appears. 

  • I need help getting my OS X Mavricks download to work and start downloading but it wont work

    i need help getting my OS X Mavricks download to work and start downloading but it wont work

    Contact http://www.apple.com/support/mac/app-store/contact/. They're responsible for getting this abysmal delivery system to work.

  • I need help getting my os x mountain lion to work for my pro tools

    I need help getting my os x mountain lion to work for my pro tools

    Since you provide no details I can do nothing but guess, so perhaps this will help:
    http://avid.force.com/pkb/articles/en_US/how_to/Upgrading-to-Mac-OS-10-8?popup=t rue&NewLang=en&DocType=1080
    http://avid.force.com/pkb/articles/en_US/compatibility/Avid-Software-and-Mac-OS- X-10-8?popup=true&NewLang=en&DocType=1083
    If you continue to have problems, you probably should contact Avid support.
    Regards.

  • I need help getting my printer to work

    I need help getting my printer to work

    http://h30434.www3.hp.com/t5/Printer-Networking-and-Wireless/Want-Good-Answers-Ask-Good-Questions/td...
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • I need help getting new authorization codes for digital copies

    I need help getting new authorization codes for digital copies of movies. Can someone help me out?

    There's a lot of results in Google when you search for this but unfortunately refreshing the page doesn't seem to generate a different code anymore. Mine also says already redeemed

  • Now i have tryied everything i need help getting premier pro trial real help pls!

    now i have tryied everything i need help getting premier pro trial real help pls!

    Hi,
    Are you facing issues installing Premiere pro trial?
    Please mention your operating system.
    Error(If you're getting any)
    Thank you,
    Mohd Naseem

  • My old iMac and OS 10.4 will not accept the New iTunes Version 10 application and I can't get past the screen offering to download iTunes 10.  This is wrong and I need help getting past this situation. Help!

    My old iMac and OS 10.4 will not accept the New iTunes Version 10 application and I can't get past the screen offering to download iTunes 10.  This is wrong and I need help getting past this situation. Help!

    Sure, you can get around it if you don't need the newest version of iTunes. I still use version 7.5 because the newer versions didn't strike me as offering anything I needed.
    If you do need a version 10-something then you will have to upgrade your operating system to Leopard (fi your computer will support it) at least.  If you need 10.5 for some reason then there's no getting around it, you will have to buy a new computer.

  • I need help getting the license number for Adobe Photoshop Elements. However, It doesn't recognize me as an authorized user. Can someone help?

    I need help getting the license number for Adobe Photoshop Elements. However, It doesn't recognize me as an authorized user. Can someone help?@

    I am having the same problem...did you ever fix it?

  • Need help getting Adobe OnLocation CS3 to work with windows 7 64 bit. Any ideas?

    Need help getting Adobe OnLocation CS3 to work with windows 7 64 bit.  The program installed ok and the S/N took.
    The program does record video and audio HDV M2T.
    The problem is video doesn't display or play back on the monitor component @ 16:9 or 720 p.  4:3....
    The scopes respond as do the audio components when recording. (with a blank monitor component).
    The video does play back on my system no problem.
    Any ideas?
    Dan

    Moving the discussion to OnLocation
    Thanks,
    Atul Saini

  • Need help getting new printer hp deskjet 3520 setup for eprint and wireless

    need help getting new printer hp deskjet 23520 stup for eprint and wireless

    Hi Pastorlee7,
    I see that you're having problems setting up your printer.  I would take a look at the document below.
    Hp deskjet 3520
    Let me know how it goes.  

  • I need help getting past the installation error "windows cannot fint TEMP file"

    I need help getting past the installation error "windows cannot find TEMP file"

    Seems like some who have tried two devices on the JMICRON IDE port have had trouble. Try without the hard drive and see if you get that error. If that is the case I would try a PATA to SATA converter for your hard drive and connect it to one of the Intel SATA Ports.
    http://www.newegg.com/Product/Product.aspx?Item=N82E16812107112
    http://www.amazon.com/ADDONICS-IDE-SERIAL-CONVERTER-ADIDESA/dp/B000090169
    http://www.compusa.com/products/product_info.asp?product_code=339900#ts
    http://www.xpcgear.com/ide2sata.html
    http://www.ubuyitdirect.com/-p-1045.html?currency=USD
    http://www.satasite.com/sata-ide-converter.htm
    http://www.pcgears.com/default.aspx?oid=187150
     

  • I haven't used an Apple computer for years. I need help getting started

    I just bought a mac mini after 20 years using a PC.  I need help getting started.  Any beginning manuals out there?  Thanks.

    New User of Apple wrote:
    I just bought a mac mini after 20 years using a PC.  I need help getting started.  Any beginning manuals out there?  Thanks.
    Welcome back. Do not overlook the Finder and individual application Help menu support. The links provided above are great starter references. With tongue in cheek, they also may not be as current as the OS X release on your mini, so expect some differences.
    Here are a litany of keyboard short-cuts, last updated in June 2012, that may prove selectively beneficial.
    For actions like copy(c), paste(v), cut(x), print(p), and select-all(a), substitute the command key instead of control key.
    If you right click on a file, this menu will seem familiar. Press the option key and notice the menu changes. If you copy a file(s) from this menu, change to the destination and then press option with the right button menu to see copy file(s) changed to move file(s).
    To quickly view a file's contents, left click on the file icon, then press the space bar.
    The native file format for OS X is PDF. Thus, when you choose to print, you also have the option to save as PDF with web links preserved.
    Enjoy your mini.

Maybe you are looking for

  • Hi all doubt on smart forms ????????

    hi , i am new to smart forms i need to create a smert form in which complex validation are all had to be implemented .. can anybody send  any nice materials where i can get a brief decsription of what a smart form is how to create it how to implement

  • Another LOV in dialog question

    Having spent some time reading blog entries and forum posts, I am still struggling with my current project. The requirements are quite simple - I have a form with two fields that are populated by dialog LOVs. To simplify this question, lets call the

  • Extractor FM - Reurn Data in Packets

    Hi, I have the following records in an internal table: <b>Sales Org Customer  Material</b> AU10             C1            M1 AU10             C2            M1 AU10             C3            M1 I have to get the Default Hire Rate (KBETR) from A835 & K

  • Volume eject from sidebar closes finder window

    after successfully upgrading 2 machines (12" pb 1.5 GHz, mac mini Core Duo 2.33 GHz) to Leopard everything works beautifully except that finder windows close when I attempt to eject a volume (CD, DVD, memory sticks, server volumes). I usually have 2

  • Debugging the Popup windows

    Hi,   When i am debugging the original program i got a popup window like address information. How can i debug the popup window...?   Is there any way except finding and keeping break point in the respective popup code... Thanks in advance. Regards, G