oracle query - saturday to Sunday is one week

SELECT
   drive_date
 , drv_date
  , CASE WHEN tot_projections    IS NOT NULL THEN tot_drives    ||'/'|| tot_projections END    AS total
FROM(
   SELECT
        drive_date
      , drv_date
      , sum(aurora_drives)      AS aurora_drives
      , sum(tp_drives)          AS tp_drives
      , sum(both_drives)        AS both_drives
      , sum(aurora_projections) AS aurora_projections
      , sum(tp_projections)     AS tp_projections
      , sum(both_projections)   AS both_projections
      , sum(tot_drives)         AS tot_drives
      , sum(tot_projections)    AS tot_projections
   FROM (
        SELECT
            drive_date      
          , to_char(drive_date,'Dy') as drv_date
              ,sum(decode(division_cd,'A',1,0)) as aurora_drives
              ,sum(decode(division_cd,'T',1,0)) as tp_drives
              ,sum(decode(division_cd,'B',1,0)) as both_drives
              ,sum(decode(division_cd,'A',projection,0)) as aurora_projections
              ,sum(decode(division_cd,'T',projection,0)) as tp_projections
              ,sum(decode(division_cd,'B',projection,0)) as both_projections
, count(drive_DATE)       AS tot_drives  
 , sum(projection) AS tot_projections
          FROM (
                  SELECT coach_drive, drive_date, division_cd, projection FROM blood_drives_temp_rollover
                                                                                                            WHERE rollover_yn = 'Y'
                  UNION ALL
                  SELECT coach_drive, drive_date, y.division_cd, projection FROM blood_drives x, sites y
                                                                         where x.site_code = y.site_code
                                    and drive_date between '01-apr-2013' and '30-apr-2013'
  ) a
          GROUP BY drive_date
        ) b
    GROUP BY drive_date,drv_date
   ) c
ORDER BY c.drive_date
;
--------------------------

DRIVE_DATE|DRV_DATE|TOTAL

4/1/2013|Mon|8/152
4/2/2013|Tue|9/235
4/3/2013|Wed|10/245
4/4/2013|Thu|14/350
4/5/2013|Fri|4/190
4/6/2013|Sat|12/215

4/7/2013|Sun|6/128
4/8/2013|Mon|9/161
4/9/2013|Tue|14/294
4/10/2013|Wed|7/396
4/11/2013|Thu|9/462
4/12/2013|Fri|7/319
4/13/2013|Sat|14/275

I want the result to be

Required format

Week 1     4/1/2013 to 4/6/2014       57/1387
 
Week 2     4/7/2013 to 4/13/2013     66/2035
data.xls
LVL 6
anumosesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MikeOM_DBACommented:
Try this:
SQL> WITH mytab (drive_date, drv_date, t1, t2)
  2    AS (SELECT TO_DATE ( '4/1/2013', 'mm/dd/yyyy'), 'Mon', 8, 152 FROM DUAL UNION ALL
  3        SELECT TO_DATE ( '4/2/2013', 'mm/dd/yyyy'), 'Tue', 9, 235 FROM DUAL UNION ALL
  4        SELECT TO_DATE ( '4/3/2013', 'mm/dd/yyyy'), 'Wed', 10, 245 FROM DUAL UNION ALL
  5        SELECT TO_DATE ( '4/4/2013', 'mm/dd/yyyy'), 'Thu', 14, 350 FROM DUAL UNION ALL
  6        SELECT TO_DATE ( '4/5/2013', 'mm/dd/yyyy'), 'Fri', 4, 190 FROM DUAL UNION ALL
  7        SELECT TO_DATE ( '4/6/2013', 'mm/dd/yyyy'), 'Sat', 12, 215 FROM DUAL UNION ALL
  8        SELECT TO_DATE ( '4/7/2013', 'mm/dd/yyyy'), 'Sun', 6, 128 FROM DUAL UNION ALL
  9        SELECT TO_DATE ( '4/8/2013', 'mm/dd/yyyy'), 'Mon', 9, 161 FROM DUAL UNION ALL
 10        SELECT TO_DATE ( '4/9/2013', 'mm/dd/yyyy'), 'Tue', 14, 294 FROM DUAL UNION ALL
 11        SELECT TO_DATE ( '4/10/2013', 'mm/dd/yyyy'), 'Wed', 7, 396 FROM DUAL UNION ALL
 12        SELECT TO_DATE ( '4/11/2013', 'mm/dd/yyyy'), 'Thu', 9, 462 FROM DUAL UNION ALL
 13        SELECT TO_DATE ( '4/12/2013', 'mm/dd/yyyy'), 'Fri', 7, 319 FROM DUAL UNION ALL
 14        SELECT TO_DATE ( '4/13/2013', 'mm/dd/yyyy'), 'Sat', 14, 275 FROM DUAL)
 15  SELECT MIN ( drive_date), MAX ( drive_date), SUM ( t1), SUM ( t2), iweek
 16      FROM (
 17          SELECT drive_date, drv_date, t1, t2, TO_CHAR ( drive_date+1, 'IW') iweek
 18            FROM mytab
 19        )
 20  GROUP BY iweek
 21  ORDER BY iweek
 22  /

MIN(DRIVE_DATE)      MAX(DRIVE_DATE)         SUM(T1)    SUM(T2) IWEEK
-------------------- -------------------- ---------- ---------- ---------
01-Apr-2013          06-Apr-2013                  57       1387 14
07-Apr-2013          13-Apr-2013                  66       2035 15

Open in new window

0
anumosesAuthor Commented:
If I have to run in toad how will I run this?
0
anumosesAuthor Commented:
I dont need to hardcode values. I think I will create a sample table with data
0
MikeOM_DBACommented:
All you need is this part:
SELECT MIN ( drive_date), MAX ( drive_date), SUM ( t1), SUM ( t2), iweek
      FROM (
          SELECT drive_date, drv_date, t1, t2, TO_CHAR ( drive_date+1, 'IW') iweek
            FROM mytab
        )
  GROUP BY iweek
  ORDER BY iweek;

Open in new window

The rest is test data...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anumosesAuthor Commented:
thanks that worked
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.