RDBMS Lab Exp 5
RDBMS Lab Exp 5
Experiment No. 5
AIM: WRITE SQL QUERIES TO IMPLEMENT THE COUNT FUNCTION
The COUNT() function in SQL is an aggregate function used to return the number of
rows that match a specified condition in a query. It is one of the most commonly
used functions when dealing with data retrieval and analysis in SQL.
Student
USN SSID
USN001 1 USN Subcode SSID Test1 Test2 Test3 FinalIA
USN008 1 USN001 SUB001 1 80 85 90 88
USN002 2 USN001 SUB004 4 75 80 78 82
USN009 2 USN002 SUB002 2 70 75 80 77
USN003 3 USN002 SUB005 5 85 90 88 92
USN010 3 USN003 SUB003 3 78 82 80 85
USN001 4 USN003 SUB006 6 65 70 72 68
USN004 4 USN004 SUB004 4 80 85 90 87
USN002 5 USN004 SUB007 7 77 80 79 83
USN005 5 USN005 SUB005 5 90 92 89 91
USN003 6 USN005 SUB008 8 74 78 76 80
USN006 6 USN006 SUB009 9 82 85 88 84
USN004 7 USN007 SUB007 7 77 80 79 82
USN007 7 USN008 SUB008 8 74 78 76 79
USN005 8 USN009 SUB010 10 88 91 90 89
USN008 8 USN010 SUB002 2 82 85 84 80
USN006 9
USN009 9
USN007 10
USN010 10
This query counts all rows in the STUDENT table using COUNT(*) and aliases the
result as TotalStudents.
Explanation:
This query counts the number of subjects (Subcode) in a specific semester (Sem),
grouping the results by semester.
Explanation:
This query joins the SEMSEC and CLASS tables to count the number of students
(USN) in each semester-section (Sem, Sec), grouping the results by semester and
section.
4. Count the number of tests (Test1, Test2, Test3) taken by students in each subject:
Explanation:
This query counts the number of occurrences of Test1, Test2, and Test3 for each
subject (Subcode) in the IAMARKS table, providing counts for each test column
separately.
SELECT Subcode, COUNT(Test1) AS NumTest1, COUNT(Test2) AS NumTest2,
COUNT(Test3) AS NumTest3
FROM IAMARKS
GROUP BY Subcode;
5. Count the number of students who have completed their FinalIA in each semester-
section:
Explanation:
This query joins SEMSEC, CLASS, and IAMARKS tables to count the number of
students (USN) who have completed their FinalIA assessment (FinalIA IS NOT
NULL) in each semester-section (Sem, Sec).