Solved

Calculating percentages per course - Oracle Query

Posted on 2016-10-20
3
46 Views
Last Modified: 2016-10-20
I have 2 problems here.
#1
Courses aren't grouping together.  My results have the same course listed several times with different count(*) per row.  Each identical course_name and course_number should be grouped into 1

#2
I need to get the percentage of ethnicity not equal to 04 per course.  So the total students.ethnicity not equal to 04 divided by the total instances of  students.student_number "for each" individual course.   The percentage I'm calculating in the query below only returns 0% or 100% which isn't correct.

Thanks so much!!!

SELECT 
CC.COURSE_NUMBER,
COURSES.COURSE_NAME,
count(*) as COURSE_ENROLLMENT,
ROUND(COUNT(CASE WHEN STUDENTS.ETHNICITY != '04' THEN 1 end)/ count(*) * 100) || '%' Minority

FROM         
STUDENTS
LEFT JOIN CC ON CC.STUDENTID = STUDENTS.ID
LEFT JOIN S_CT_STU_DEMOGRAPHICS_X ON STUDENTS.DCID = S_CT_STU_DEMOGRAPHICS_X.STUDENTSDCID
LEFT JOIN COURSES ON CC.COURSE_NUMBER = COURSES.COURSE_NUMBER

WHERE     
CC.TERMID IN ('2600','2601','2602')
AND STUDENTS.SCHOOLID IN ('61', '62') 
AND STUDENTS.ENROLL_STATUS = 0
AND COURSES.GRADESCALEID in (110,123)

GROUP BY
CC.COURSE_NUMBER,
STUDENTS.ETHNICITY,
COURSES.COURSE_NAME

ORDER BY CC.COURSE_NUMBER

Open in new window

0
Comment
Question by:Basssque
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 41852189
>>My results have the same course listed several times

It is probably because you are grouping on ETHNICITY.  You will end up with one course_number and course_name row for each ETHNICITY value.



If you want a copy/paste solution, please provide sample data and expected results.
0
 
LVL 32

Expert Comment

by:awking00
ID: 41852194
Can you provide some sample data (dummy it up if it's proprietary) for that query and what you expect the percentages to be?
0
 

Author Closing Comment

by:Basssque
ID: 41852195
I just had to remove ethnicity from the group by clause and everything now works as expected.  Thanks so much!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Workhours Count beetween Workhours 3 25
Need help with a Stored Proc on Sql Server 2012 4 28
sum of columns in a row in oracle 3 32
date show only hh:mm 2 25
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to recover a database from a user managed backup

790 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