Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding Total Rows to SQL Query

b7d712a9-109f-4486-8d04-1cc5ca0a54f3Oct 20 2015 — edited Oct 20 2015

Hi All,

I currently have the following SQL Statement:

SELECT B.MDA_LEV3_DEPT_NAME AS "EVP Area",

       COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'C' THEN 1 END) AS Approved,

       COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'A' THEN 1 END) AS "In Progress",

       COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'E' THEN 1 END) AS Draft

  FROM PS_MDA_EPAF_RQST Z,

       PS_MDA_EMPLOYEES B

       --PS_MDA_EPAF_WFXREF T

WHERE MDA_EPAF_STATUS IN ('C','A','E')

   --AND T.ORIGINATORID = Z.USERID

   AND Z.USERID = B.EMPLID

   AND Z.HRS_SUBMITTED_DTTM between to_date(:d1, 'dd-mon-yy' )

                 and to_date(:d2, 'dd-mon-yy' )

   --AND Z.TRANSACTION_NBR = T.TRANSACTION_NBR

GROUP BY B.MDA_LEV3_DEPT_NAME

ORDER BY B.MDA_LEV3_DEPT_NAME

Which produces the following results:

   

EVP AreaApprovedIn ProgressDraft
Academic Affairs Sr VP Office400
Cancer Medicine3012
Cancer Medicine - Research4111
Cancer Prev & Pop Sciences300
Cancer Prev & Pop Sciences-Res100
Diagnostic Imaging200
Information Services16140
Internal Medicine410
Pathology/Lab Medicine200
Pathology/Lab Medicine - Resch100
Pediatrics1101
Provost and EVP Departments100
Radiation Oncology26025
Radiation Oncology - Research200
Regulatory Affairs100
Surgery400
Vice Provost Clinical Researc100
Vice Provost Science3911

Goal: I want to add an additional column to show the total for each EVP area and I want to add a final row at the bottom to show the totals for Approved, In Progress, and Draft. Any help is much appreciated, thank you for your time.

Trey

This post has been answered by Etbin on Oct 20 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2015
Added on Oct 20 2015
6 comments
808 views