DBMS Practice
Experiment
Design 7 tables as per the
given requirements, with at least 10 rows per table, including primary
keys and foreign keys wherever appropriate.
Your tables should be as
follows (attributes are suggested but you may modify them if needed):
Table: Department
|
Table: Student
|
Table: Faculty
|
Table: Course
|
Table: Enrollment
|
Table: Exam
|
Table: Result
|
Keys and
Relationships
·
Department
→ PK: dept_id
·
Student
→ FK: dept_id
·
Faculty
→ FK: dept_id
·
Course
→ FK: dept_id
,
faculty_id
·
Enrollment
→ FK: student_id
,
course_id
·
Exam
→ FK: course_id
·
Result
→ FK: student_id
,
course_id
,
exam_id
Write SQL queries for the
following:
1.
List all students in the
'Computer Science' department.
SELECT first_name, last_name
FROM Student S
JOIN Department
D ON S.dept_id = D.dept_id
WHERE
D.dept_name = 'Computer Science';
2. Find
the total number of students enrolled in each course.
SELECT C.course_name, COUNT(E.student_id)
AS total_students
FROM Enrollment
E
JOIN Course C ON E.course_id = C.course_id
GROUP BY C.course_name;
3. Retrieve
faculty names and the courses they teach.
SELECT F.first_name, F.last_name, C.course_name
FROM Faculty F
JOIN Course C ON F.faculty_id = C.faculty_id;
4. Get
the details of students who have less than 75% attendance.
SELECT S.first_name, S.last_name,
E.attendance_percentage
FROM Enrollment
E
JOIN Student S ON E.student_id = S.student_id
WHERE
E.attendance_percentage < 75;
5. Find
students who have failed in any course.
SELECT S.first_name, S.last_name,
E.attendance_percentage
FROM Enrollment
E
JOIN Student S ON E.student_id = S.student_id
WHERE
E.attendance_percentage < 75;
6. Display
department-wise count of faculty members.
SELECT D.dept_name, COUNT(F.faculty_id)
AS faculty_count
FROM Faculty F
JOIN Department
D ON F.dept_id = D.dept_id
GROUP BY D.dept_name;
7. List
courses offered in semester 5 with more than 3 credits.
SELECT course_name, credits
FROM Course
WHERE semester
= 5 AND credits > 3;
8. Retrieve
students along with the courses they are enrolled in.
SELECT S.first_name, S.last_name, C.course_name
FROM Enrollment
E
JOIN Student S ON E.student_id = S.student_id
JOIN Course C ON E.course_id = C.course_id;
9. Get
the average marks of each student across all courses.
SELECT S.first_name, S.last_name, AVG(R.marks_obtained) AS avg_marks
FROM Result R
JOIN Student S ON R.student_id = S.student_id
GROUP BY S.first_name, S.last_name;
10. Find
the top 3 students with the highest average marks.
SELECT
S.student_id, S.first_name, S.last_name, AVG(R.marks_obtained)
AS avg_marks
FROM Result R
JOIN Student S
ON R.student_id = S.student_id
GROUP BY S.student_id, S.first_name, S.last_name
ORDER BY avg_marks DESC
LIMIT 3;
Comments
Post a Comment