0% found this document useful (0 votes)
8 views

RDBMS Lab Exp 5

The document outlines SQL queries to implement the COUNT() function for various data retrieval tasks in a relational database management system. It includes a schema for students, subjects, and marks, and provides specific queries to count total students, subjects per semester, students per semester-section, tests taken, and students who completed their FinalIA. Each query is accompanied by an explanation of its purpose and structure.

Uploaded by

deviladode2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

RDBMS Lab Exp 5

The document outlines SQL queries to implement the COUNT() function for various data retrieval tasks in a relational database management system. It includes a schema for students, subjects, and marks, and provides specific queries to count total students, subjects per semester, students per semester-section, tests taken, and students who completed their FinalIA. Each query is accompanied by an explanation of its purpose and structure.

Uploaded by

deviladode2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

B.

TECH 4th CSE

RELATIONAL DATABASE MANAGEMENT SYSTEM LAB

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.

Consider the following Schema:


STUDENT (USN, SName, Address, Phone, Gender)
SEMSEC (SSID, Sem, Sec)
CLASS (USN, SSID)
SUBJECT (Subcode, Title, Sem, Credits)
IAMARKS (USN, Subcode, SSID, Test1, Test2, Test3, FinalIA)

Student

USN SName Address Phone, Gender


USN001 Alice Johnson 123 ElmSt 555-0101 F
USN002 Bob Smith 456 Oak St 555-0102 M
USN003 Carol White 789 Pine St 555-0103 F
USN004 David Brown 101 MapleSt 555-0104 M
USN005 Eve Davis 202 Birch St 555-0105 F
USN006 Frank Green 303 Cedar St 555-0106 M
USN007 Grace Lee 404 Elm St 555-0107 F
USN008 Henry Wilson 505 Oak St 555-0108 M
USN009 Ivy Martin 606 Pine St 555-0109 F
USN010 John Taylor 707 MapleSt 555-0110 M
Semsec Subject

SSID SEM SEC Subcode Title Sem Credits


1 1 A SUB001 Introduction to Programming 1 4
2 1 B SUB002 Data Structures 1 4
3 1 C SUB003 Algorithms 1 3
4 2 A SUB004 Database Systems 2 4
5 2 B SUB005 Operating Systems 2 3
6 2 C SUB006 Computer Networks 3 4
7 3 A SUB007 Software Engineering 3 3
8 3 B SUB008 Web Development 4 4
9 3 C SUB009 Artificial Intelligence 4 4
10 4 A SUB010 Machine Learning 4 3
Class IAMARKS

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

1. Count the total number of students:


2. Count the number of subjects offered in a specific semester:
3. Count the number of students enrolled in each semester-section (Sem, Sec):
4. Count the number of tests (Test1, Test2, Test3) taken by students in each subject:
5. Count the number of students who have completed their FinalIA in each semester-
section:
QUERIES:

1. Count the total number of students:

This query counts all rows in the STUDENT table using COUNT(*) and aliases the
result as TotalStudents.

SELECT COUNT(*) AS TotalStudents


FROM STUDENT;
Explanation:

2. Count the number of subjects offered in a specific semester:

Explanation:

This query counts the number of subjects (Subcode) in a specific semester (Sem),
grouping the results by semester.

SELECT Sem, COUNT(*) AS NumSubjects


FROM SUBJECT
WHERE Sem = '2nd Semester' -- Adjust the semester as needed
GROUP BY Sem;

3. Count the number of students enrolled in each semester-section (Sem, Sec):

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.

SELECT Sem, Sec, COUNT(*) AS NumStudents


FROM SEMSEC s
JOIN CLASS c ON s.SSID = c.SSID
GROUP BY Sem, Sec;

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).

SELECT s.Sem, s.Sec, COUNT(*) AS NumStudentsFinalIA


FROM SEMSEC s
JOIN CLASS c ON s.SSID = c.SSID
JOIN IAMARKS i ON c.USN = i.USN AND c.SSID = i.SSID
WHERE i.FinalIA IS NOT NULL
GROUP BY s.Sem, s.Sec;

You might also like