Solved

oracle query

Posted on 2015-01-05
3
113 Views
Last Modified: 2015-01-06
CREATE TABLE TAB1
(
  DRIVE_DATE      DATE                          NOT NULL,
  AREA_REP_NO     NUMBER(4)                     NOT NULL,
  PROCEDURE_CODE  VARCHAR2(5 BYTE)
)




Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'DR');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 15, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 15, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 15, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 15, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'DR');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'DR');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 8, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 12, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 12, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 12, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'DR');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
Insert into TAB1
   (DRIVE_DATE, AREA_REP_NO, PROCEDURE_CODE)
 Values
   (TO_DATE('01/02/2015 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 10, 'WB');
COMMIT;

Open in new window


select drive_date,area_rep_no,
       procedure_code,count(*) as cnt
  from tab1
 group by drive_date,area_rep_no,
       procedure_code 

Open in new window


Need help in the count

If procedure_code is DR (double red)  then I need count multiplied by 2. For WB (whole blood) its 1
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
3 Comments
 
LVL 35

Accepted Solution

by:
johnsone earned 250 total points
ID: 40531733
I didn't test it, but this should do it:

SELECT drive_date, 
       area_rep_no, 
       procedure_code, 
       SUM(CASE 
             WHEN procedure_code = 'DR' THEN 2 
             ELSE 1 
           END) AS cnt 
FROM   tab1 
GROUP  BY drive_date, 
          area_rep_no, 
          procedure_code 

Open in new window

0
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 250 total points
ID: 40531742
This should work!
  SELECT Drive_Date
       , Area_Rep_No
       , Procedure_Code
       , DECODE ( Procedure_Code, 'DR', 2, 1 ) * COUNT ( * ) AS Cnt
    FROM Tab1
GROUP BY Drive_Date, Area_Rep_No, Procedure_Code
/

Open in new window

0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 40533313
thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

734 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