?
Solved

oracle query

Posted on 2014-04-30
4
Medium Priority
?
309 Views
Last Modified: 2014-04-30
select drive_date,drive_id,to_char(drive_date,'Day'),coach_drive
from blood_drives
where drive_date between '01-jun-2014' and '31-aug-2014'
and coach_drive in ('C','M')


DRIVE_DATE,DRIVE_ID,TO_CHAR(DRIVE_DATE,'DAY'),COACH_DRIVE
6/1/2014,2024075,Sunday   ,C
6/1/2014,2023621,Sunday   ,C
6/2/2014,2024011,Monday   ,M
6/2/2014,2024078,Monday   ,C
6/2/2014,2023437,Monday   ,M
6/2/2014,2023211,Monday   ,M
6/3/2014,2024083,Tuesday  ,C
6/3/2014,2024084,Tuesday  ,C
6/3/2014,2023684,Tuesday  ,C
6/3/2014,2024079,Tuesday  ,C
6/4/2014,2024164,Wednesday,C
6/4/2014,2024158,Wednesday,C
6/4/2014,2024159,Wednesday,C
6/4/2014,2024160,Wednesday,C
6/5/2014,2023975,Thursday ,C
6/5/2014,2023161,Thursday ,C
6/5/2014,2024166,Thursday ,C
6/6/2014,2024028,Friday   ,C
6/7/2014,2022771,Saturday ,C
6/7/2014,2024167,Saturday ,C
6/7/2014,2023431,Saturday ,C
6/8/2014,2024169,Sunday   ,C
6/8/2014,2024170,Sunday   ,C
6/9/2014,2024447,Monday   ,C
6/9/2014,2024485,Monday   ,C
6/9/2014,2022854,Monday   ,M
6/9/2014,2024172,Monday   ,C
6/9/2014,2023246,Monday   ,C

The user want this report in this format

Day of the week    count(coaches)   count(minis)

Sunday                          2
Monday                         1                        3
Tuesday                        4
Wednesday                   4        


----- etc
0
Comment
Question by:anumoses
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40032266
Try this:

select TO_CHAR(DRIVE_DATE,'DAY'),
    count(case when COACH_DRIVE = 'C' then 'C' end),
    count(case when COACH_DRIVE = 'M' then 'M' end)
from blood_drives
where drive_date between '01-jun-2014' and '31-aug-2014'
and coach_drive in ('C','M')
group by TO_CHAR(DRIVE_DATE,'DAY')
0
 
LVL 6

Author Comment

by:anumoses
ID: 40032489
This query works perfectly fine.
 Can we add another column totals for each day of the week
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1000 total points
ID: 40032505
>> Can we add another column totals for each day of the week

You can add whatever you want.  Should just be a regular count?

Try this:
select TO_CHAR(DRIVE_DATE,'DAY'),
    count(case when COACH_DRIVE = 'C' then 'C' end),
    count(case when COACH_DRIVE = 'M' then 'M' end),
    count(*)
from blood_drives
where drive_date between '01-jun-2014' and '31-aug-2014'
and coach_drive in ('C','M')
group by TO_CHAR(DRIVE_DATE,'DAY')
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 40032901
thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question