This document contains 8 SQL queries that:
1) Count the number of teachers assigned to each teacher ID.
2) Count the number of students named "John" in each class.
3) Assign unique roll numbers to students after sorting by full name and class.
4) Calculate the ratio of male to female students in each class.
5) Calculate the average years of experience for teachers.
6) Display student names, exam names, subjects, marks and mark percentages.
7) Display student IDs, exam IDs and performance percentages for specific exams.
8) Rank students in each class by total marks in an exam.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
187 views
Accenture Solution
This document contains 8 SQL queries that:
1) Count the number of teachers assigned to each teacher ID.
2) Count the number of students named "John" in each class.
3) Assign unique roll numbers to students after sorting by full name and class.
4) Calculate the ratio of male to female students in each class.
5) Calculate the average years of experience for teachers.
6) Display student names, exam names, subjects, marks and mark percentages.
7) Display student IDs, exam IDs and performance percentages for specific exams.
8) Rank students in each class by total marks in an exam.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
1.
Select teacher_id, Count(*) from teacher_allocation_table group by teacher_id
2. select class_id, count(student_name) as no_of_johns from student where student_name like "%John%" group by class_id;
3. /*Create a roll number column after sorting the data by fullname*/
SELECT FullName, class, (SELECT Count(*) from Student as s2 where s1.FullName > s2.FullName and s1.class = s2.class)+1 as UniqueRollNo FROM Student as S1 Order By 3; ------------ select row_number() over (partition by class order by fullname) as roll_no,id, fullname from student;
4. SELECT class_id, sum(IF(gender = "M", 1, 0))/ sum(IF(gender="F",1,0)) as
6. SELECT student_name, exam_name, exam_subject, marks, marks/total_marks as
MarksVsTotalMarks FROM student_table st, exam_paper_table ept, exam_table et WHERE st.student_id = ept.student_id and ept.exam_id = et.exam_id order by 1, 2, 3
7. SELECT st.student_id, et.exam_id,
Format("Percent",marks/total_marks) as performance FROM student_table st, exam_paper_table ept, exam_table et WHERE st.student_id = ept.student_id and ept.exam_id = et.exam_id and st.student_id IN (1,4,9,16,25) and exam_name = "Quarterly" order by 1, 2, 3;
8. SELECT ct.class_id, st.student_id,
dense_rank() over (partition by class order by sum(marks) DESC) as DRank FROM student_table st, exam_paper_table ept, exam_table et, class_table ct WHERE ct.class_id = st.class_id, st.student_id = ept.student_id and ept.exam_id = et.exam_id and exam_name = "Half-yearly" Group By ct.class_id, st.student_id order by 1, 3 DESC;