Ivy Professional School
Rating
Learning/SQL Data Drill #20

Student Screening and Failed Subject Analysis

Last updated

Identify students who cleared all subjects, calculate their percentage, and list failed subjects for students who did not qualify.

SQLAdvancedCTEUNION ALLCASE WHENGROUP_CONCATConditional LogicRankingScreening Analysis

Your Objective

Identify students who cleared all subjects, calculate their percentage, and list failed subjects for students who did not qualify.

The Setup

Your dataset contains three student screening tables: 1. A Students table with roll numbers and student names 2. A Scores table with marks across six subjects 3. A Subjects table with subject names and pass marks Only students who pass all six subjects will be considered for the interview round. The company also wants to know the subjects failed by students who did not qualify. There is an option between Subject5 and Subject6. If a student has taken both, the higher score between Subject5 and Subject6 should be considered while calculating total percentage.

Table Schema

Students
ColumnTypeKey / Notes
Roll_NoVARCHAR(20)
NameVARCHAR(100)
Scores
ColumnTypeKey / Notes
Student_IDVARCHAR(20)
Subject1INT
Subject2INT
Subject3INT
Subject4INT
Subject5INT
Subject6INT
Subjects
ColumnTypeKey / Notes
IDVARCHAR(10)
SubjectVARCHAR(100)
Pass_MarksINT

Sample Data

Subjects — 6 rows

IDSubjectPass_Marks
S1Excel50
S2SQL50
S3Python40
S4Hadoop35
S5Power BI40
S6Tableau40

Students — 6 rows

Roll_NoName
2GR5CS011Aarav Sharma
2GR5CS012Priya Gupta
2GR5CS013Rohit Singh
2GR5CS014Anjali Patel
2GR5CS015Karan Mehta
2GR5CS016Nisha Reddy

Scores — 6 rows

Student_IDSubject1Subject2Subject3Subject4Subject5Subject6
2GR5CS01175305744356
2GR5CS012702144639985
2GR5CS01321966879178
2GR5CS0148446203410038
2GR5CS015319063609080
2GR5CS01695519262621

Your Task

Student Screening Analysis: Which students passed the screening test, what percentage did they score, and which subjects did failed students fail in? The final result table should have Roll_No, Name, Percentage_marks, Failed_subjects, and Status columns.

Your output should look like this (partial example):

Roll_NoNamePercentage_marksFailed_subjectsStatus
2GR5CSxxxStudent Name00.00NULLPassed
2GR5CSxxxStudent Name00.00SQL, PythonFailed

Before You Solve

  • →Use UNION ALL to unpivot Subject1 through Subject6 into subject-wise rows.
  • →Join the unpivoted marks with Subjects to compare each score with its pass mark.
  • →Use GREATEST(Subject5, Subject6) while calculating percentage because Subject5 and Subject6 are optional alternatives.
  • →Use GROUP_CONCAT with CASE WHEN to list only failed subjects.
  • →Order passed students first, then sort passed students by percentage in descending order.
Explore Enterprise Solutions