Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Calculating percentages per course - Oracle Query

Posted on 2016-10-20
Medium Priority
59 Views
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

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

ORDER BY CC.COURSE_NUMBER
``````
0
Question by:Basssque
[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

LVL 77

Accepted Solution

slightwv (䄆 Netminder) earned 2000 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

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

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

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
###### Suggested Courses
Course of the Month9 days, 23 hours left to enroll