anumoses
asked on
Oracle query
select to_char(drive_date,'MON') date_label,
to_date(to_char(drive_date ,'MON'),'M ON') date_order,
sum(nvl(actual_draw,projec tion)) as Actual
from blood_drives
where drive_date between '01-jan-2011' and '31-dec-2011'
and drive_cancelled is null
and area_rep_no = 11
group by area_rep_no, to_date(to_char(drive_date ,'MON'),'M ON'),
to_char(drive_date,'MON')
-------------------------- -----
select to_char(drive_date,'MON') date_label,
to_date(to_char(drive_date ,'MON'),'M ON') date_order,
sum(nvl(actual_draw,projec tion)) as Actual
from blood_drives
where drive_date between '01-jan-2012' and '31-dec-2012'
and drive_cancelled is null
and area_rep_no = 11
group by area_rep_no, to_date(to_char(drive_date ,'MON'),'M ON'),
to_char(drive_date,'MON')
Result of 1st query
I have enclosed the results and what is expected in the excel spread sheet that is attached
result-1st-query.xls
to_date(to_char(drive_date
sum(nvl(actual_draw,projec
from blood_drives
where drive_date between '01-jan-2011' and '31-dec-2011'
and drive_cancelled is null
and area_rep_no = 11
group by area_rep_no, to_date(to_char(drive_date
to_char(drive_date,'MON')
--------------------------
select to_char(drive_date,'MON') date_label,
to_date(to_char(drive_date
sum(nvl(actual_draw,projec
from blood_drives
where drive_date between '01-jan-2012' and '31-dec-2012'
and drive_cancelled is null
and area_rep_no = 11
group by area_rep_no, to_date(to_char(drive_date
to_char(drive_date,'MON')
Result of 1st query
I have enclosed the results and what is expected in the excel spread sheet that is attached
result-1st-query.xls
ASKER
select to_char(drive_date,'MON') date_label,
to_date(to_char(drive_date ,'MON'),'M ON') date_order,
sum(nvl(actual_draw,projec tion)) as Actual
from blood_drives
where drive_date between '01-jan-2011' and '31-dec-2011'
and drive_cancelled is null
and area_rep_no = 11
group by area_rep_no, to_date(to_char(drive_date ,'MON'),'M ON'),
to_char(drive_date,'MON')
How do I get date_order to be 2011?
to_date(to_char(drive_date
sum(nvl(actual_draw,projec
from blood_drives
where drive_date between '01-jan-2011' and '31-dec-2011'
and drive_cancelled is null
and area_rep_no = 11
group by area_rep_no, to_date(to_char(drive_date
to_char(drive_date,'MON')
How do I get date_order to be 2011?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry I am at 10G
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
Then, it looks like the output you want is what is called a "matrix" or "cross-tab" report. Some reporting tools (Crystal Reports, Oracle Reports, etc.) can produce this kind of output, but simple SQL queries cannot. There may be an advanced SQL keyword that can be used these days to do that, but I haven't used it.
In the "old days", if you wanted to produce this kind of output from a single query without a reporting tool, you had to use "case" or "decode" and hard-code separate sections in your query for each additional column that you wanted in the output.