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

DBA Lab Ass 2

The document contains SQL code to create tables for students, faculty, departments, and GPAs in a database. It then provides sample data by inserting records into each table. It concludes with 5 SQL queries run against the tables along with the output of each query. The queries return the names and addresses of students under 24 years old, the minimum student age, details of students in the CS department, faculty names and number of students, and departments with at least 2 students.

Uploaded by

Tao Cache
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

DBA Lab Ass 2

The document contains SQL code to create tables for students, faculty, departments, and GPAs in a database. It then provides sample data by inserting records into each table. It concludes with 5 SQL queries run against the tables along with the output of each query. The queries return the names and addresses of students under 24 years old, the minimum student age, details of students in the CS department, faculty names and number of students, and departments with at least 2 students.

Uploaded by

Tao Cache
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Name: Talha Jamil

Sap: 70078198
Sec: D
TABLE:-

CREATE TABLE student (


sID int(10),
sName varchar(25),
sAddress varchar(50),
sAge int(2),
departID int (10),
fID int (10)
);
CREATE TABLE faculty (
fID int(10),
fName varchar(25),
departID int (10)
);
CREATE TABLE department (
departID int (10),
departName varchar(30)
);
CREATE TABLE gpa (
gID int(10),
sID int(10),
gradeDescription varchar(10)
);
Student TABLE:-

INSERT INTO `student`(`sID`, `sName`, `sAddress`, `sAge`, `departID`, `fID`)


VALUES (111,'Hassan','Model Town',23,1001,551);
INSERT INTO `student`(`sID`, `sName`, `sAddress`, `sAge`, `departID`, `fID`)
VALUES (112,'Umair','Faisal Town',25,1001,552);
INSERT INTO `student`(`sID`, `sName`, `sAddress`, `sAge`, `departID`, `fID`)
VALUES (113,'Imran','Johar Twon',22,1002,553);
INSERT INTO `student`(`sID`, `sName`, `sAddress`, `sAge`, `departID`, `fID`)
VALUES (114,'Talha Jamil','Lahore',20,1001,551);
INSERT INTO `student`(`sID`, `sName`, `sAddress`, `sAge`, `departID`, `fID`)
VALUES (115,'Talha Jamil','Lahore',21,1002,551);
faculty TABLE:-

INSERT INTO `faculty`(`fID`, `fName`, `departID`)


VALUES (551,'Sir. Ishaq Raza',1001);
INSERT INTO `faculty`(`fID`, `fName`, `departID`)
VALUES (552,'Sir. Aftab Alam',1002);
INSERT INTO `faculty`(`fID`, `fName`, `departID`)
VALUES (553,'Sir. Adnan Noor',1001);
department TABLE:-

INSERT INTO `department`(`departID`, `departName`)


VALUES (1001,'CS');
INSERT INTO `department`(`departID`, `departName`)
VALUES (1002,'EE');
INSERT INTO `department`(`departID`, `departName`)
VALUES (1003,'BBA');
gpa TABLE:-

INSERT INTO `gpa`(`gID`, `sID`, `gradeDescription`)


VALUES (1,113,'A');
INSERT INTO `gpa`(`gID`, `sID`, `gradeDescription`)
VALUES (2,111,'A-');
INSERT INTO `gpa`(`gID`, `sID`, `gradeDescription`)
VALUES (3,112,'B+');
INSERT INTO `gpa`(`gID`, `sID`, `gradeDescription`)
VALUES (4,114,'D');
INSERT INTO `gpa`(`gID`, `sID`, `gradeDescription`)
VALUES (5,115,'C')
SQL quaries along with output:

1.Output the name of student along their address with age less the 24.

SELECT sName, sAddress, sAge


FROM student
WHERE sAge<24
2.Output the minimum age in student table.

SELECT MIN(sAge)
FROM student;
3.Output the name of student, address and age belongs to ‘CS’ department.

SELECT student.sName, student.sAddress, student.sAge


FROM student, department
WHERE student.departID=department.departID AND department.departName='CS';

4.Output the name of each faculty member in DESC and total number of
student studying under their guidance.

SELECT faculty.fName, COUNT(student.sID)


FROM faculty, student
WHERE student.fID=faculty.fID
GROUP BY(faculty.fID)
ORDER BY(faculty.fName) DESC;
5.Output the name of each department which contains at least 2 students
enrolled in it.

SELECT department.departName
FROM department, student
WHERE department.departID=student.departID
GROUP BY(student.departID)
HAVING COUNT(student.sID)>=2;

You might also like