Name: Aadarsh Verma
Roll Number: 12112120 (CSB-6)
Ex.2
CAR (Registration-No, Chassis-No, Engine-No, Company-Name, Model, Year-
Model, Price)
PERSON ( Aadhar-No, Name, Address, City)
OWN-BY (Registration-No, Aadhar-No)
DRIVER (License-No., Date-of-Issue, Valid-up-to, Aadhar-No.)
Code :
CREATE DATABASE experiment1;
use experiment1;
create table car
(chasis_no varchar(45),
engine_no varchar(45),
reg_no varchar(45),
comapny varchar(20),
model char(20),
year_manu int,
price float);
describe car;
create table person
(adhaar float,
name_p varchar(30),
address varchar(50),
city varchar(40));
describe person;
create table own_by
(reg_no varchar(45),
adhaar float);
describe own_by;
create table driver
(license_no float,
date_of_issue float,
valid_upto float,
adhaar float);
describe driver;
use experiment1;
insert into car
values('sdfguibl','a7852413',’a70245’,’hundai’,’creta’,2017,700000);
insert into person
values('1234567890',’Aady’,’21-D’,’faridabad’);
insert into driver
values(12345678,12081995,01042025,123456789012);
insert into own_by
values(’a70245’,'1234567890');
Output-
Car database
Person:
Own by:
Driver:
STUDENT (Roll-No., Name, Father-Name, Mother-Name, City, Dept-Code)
DEPARTMENT (Dept-Code, Dept-Name, Dept-Head)
PROGRAM (Degree-Name, Discipline-Name)
ENROLLED (Roll-No., Degree-Name)
create database experiment1_2;
use experiment1_2;
create table student
(roll int ,
name_s varchar(45),
father_name varchar(45),
mother_name varchar(45),
city varchar(50),
dep_code char(20));
create table department
(dep_code char(20),
dep_name varchar(30),
dep_head varchar(20));
create table enrolled
(roll int,
deg_name varchar(20));
create table program
(deg_name varchar(20),
dis_name varchar(20));
describe student;
describe department;
describe enrolled;
describe program;
insert into student
values(12112120,'Aadarsh',’Mukesh’,'Meena',’fbd’,'cspc');
insert into department
values('cspc','computer department','ak singh');
insert into enrolled
values(12112120,'computer department');
insert into program
values('btech','computer engineering');
department:
Enrolled:
Program:
Student:
COMPANY (C-Registration-No, C-Name, Address)
PERSON ( Aadhar-No, Name, Father-Name, Date-of-Birth, Address)
OWNED-BY (C-Registration-No, Aadhar-No)
create database experiment1_3;
use experiment1_3;
create table company
(c_reg_no varchar(45),
c_name char(20),
address varchar(30));
create table owned_by
(c_reg_no varchar(45),
adhaar float);
create table person
(adhaar float,
name varchar(30),
father_name varchar(30),
dob float,
address varchar(40));
insert into company
values(‘424vc’,’Aady’s,'fbd');
insert into owned_by
values((‘424vc’,1234567890);
insert into person
values(1234567890,'Aadarsh','Mukesh',230820003,'fbd');
Output:
Company:
Owned by:
Person:
BOOK (Access-No., Title, Author, Subject-Code)
MEMBER (Membership-No., Type)
EMPLOYEE (Emp-Code, Name, Designation, Dept-Name)
STUDENT (Roll-No., Dept-Name, Program)
BOOKS-ISSUE (Register-Entry-No., Access-No., Membership-No., Date-
of-Issue)
BOOKS-RETURN (Access-No., Return-Date, Comment)
Code:
create database experiment1_4;
use experiment1_4;
create table book
(access_no int,
author varchar(20),
title varchar(20),
subject_code char(10));
create table member_l
(mem_no int,
type_mem varchar(20));
create table student
(roll int,
dept_name varchar(20),
program varchar(10));
create table employee
(empl_code int,
name_e varchar(25),
designation varchar(15),
dept_name varchar(20));
create table book_issue
(reg_entry_no int,
access_no int,
mem_no int,
date_issue int);
create table book_return
(access_no int,
date_return int,
comment_return varchar(50));
insert into book
values(1234,'rohan','my life','cspc');
insert into member_l
values(789,'student'),
(456,'employee');
insert into student
values(12112127,'computer','btech');
insert into employee
values(123,'rohan','director','computer');
insert into book_issue
values(21,1234,789,30082022);
insert into book_return
values(1234,30082022,'book returned in good condition');
book:
Book issue:
Book return:
Employee:
Member:
Student:
Exp3:
Create a database for the following relational schema and insert tuples.
STUDENT (Roll-No, Name, Gender, Degree, Semester, Contact no, email-id, Guide-No, Group-Code,
Project-No)
GUIDE (Guide-No, Guide-name, Guide-research-area, Email-id)
PROJECT (Project-No, Project-title, Project-area, Project-Year-Month, Guide-No, Group-Code)
GROUPS (Group-Code, No-of -Students)
STUDENT (Roll-No, Name, Gender, Degree, Semester, Contact no, email-id, Guide-No, Group-Code,
Project-No)
GUIDE (Guide-No, Guide-name, Guide-research-area, Email-id)
PROJECT (Project-No, Project-title, Project-area, Project-Year-Month, Guide-No, Group-Code)
GROUPS (Group-Code, No-of -Students)
Code:
create database Experiment3;
use Experiment3;
create table students
(roll_number int unique,
s_name varchar(45) not null ,
gender char check(gender in ('M','F')),
degree varchar(10) not null,
sem int,
contact double,
email varchar(20) check(email like "%_@_%._%"),
group_code char(10),
guide_no int,
project_no int,
primary key (roll_number),
foreign key(group_code)references groupss(group_code),
foreign key(guide_no)references guide(guide_no),
foreign key(project_no)references project(project_no)
);
describe students;
describe guide;
insert into students
values(12112127,"rohan kumar",'M',"Btech",3,8708322262,"[email protected]");
create table project
(project_no int primary key,
project_title varchar(40) not null,
project_area varchar(30) not null,
project_year_month varchar(6) check (project_year_month like "_______"),
guide_no int not null,
group_code char(10),
foreign key(group_code)references groupss(group_code),
foreign key(guide_no)references guide(guide_no)
);
create table guide
(guide_no int primary key,
guide_name varchar(30) not null,
guide_research_area varchar(40),
email varchar(20) check(email like "%_@_%._%")
);
create table groupss
(group_code char(10) primary key,
no_of_students int
);
insert into groupss
values("cspc1",3);
insert into guide
values(1,"SK jain","dbms","
[email protected]");
insert into project
values(23,"creating databases","dbms",1,"cspc1","202209");
insert into students
values(12112127,"rohan kumar",'M',"Btech",3,8708322262,"[email protected]","cspc1",1,23);
insert into guide
values(11,"Ram mohan","dbms","[email protected]");
insert into groupss
values("cspc2",3);
insert into project
values(25,"creating tables","dbms",1,"cspc2","202209");
insert into project
values(26,"creating tables","dbms",11,"cspc2","202209");
insert into students
values(110012,"ramesh kumar",'M',"Btech",3,8708234862,"[email protected]","cspc2",1,25);
update students
set guide_no = 11
where roll_number = 110012;
insert into guide
values(15,"mukesh","coa","[email protected]");
insert into guide
values(10,"Rohit","dsa","[email protected]");
insert into students
values(110013,"rohit",'M',"Btech",3,8708234862,"[email protected]","cspc2",15,27);
insert into students
values(110014,"aman",'M',"Btech",3,8744542348,"[email protected]","cspc2",15,27);
insert into students
values(110015,"tripathi",'M',"Btech",3,8708934662,"[email protected]","cspc2",15,27);
insert into project
values(27,"address mode","coa",15,"cspc2","202209");
insert into groupss
values("cspc3",3);
insert into groupss
values("cspc4",3);
insert into groupss
values("cspc5",3);
insert into groupss
values("cspc6",3);
insert into groupss
values("cspc7",3);
insert into guide
values(16,"pooja","ai","[email protected]"),
(17,"divya","networking","[email protected]"),
(18,"ankit","coa","[email protected]"),
(19,"rohan","programming","[email protected]"),
(20,"mayank","programming","[email protected]"),
(21,"jatin","networking","[email protected]");
insert into project
values(7,"gr23","ai",16,"cspc3",202208),
(8,"g65","ai",16,"cspc1",202208),
(5,"g76","networking",17,"cspc4",201906),
(12,"vaayuu","coa",18,"cspc3",201906),
(21,"teja","programming",19,"cspc5",201903),
(29,"rafale","networking",17,"cspc1",202203),
(30,"pqr","networking",17,"cspc7",201812),
(31,"abc","ai",16,"cspc6",202205);
insert into students
values(12112100,"manish",'M',"btech",3,8646846846,"[email protected]","cspc3",18,12),
(12112101,"abhishek",'M',"btech",3,5415416535,"[email protected]","cspc4",17,30),
(12112102,"manish",'M',"btech",3,8646846846,"[email protected]","cspc3",18,12),
(12112103,"yuvraj",'M',"btech",3,5415416535,"[email protected]","cspc4",17,30),
(12112104,"aayush",'M',"btech",3,54965416535,"[email protected]","cspc5",19,21),
(12112105,"aayush2",'M',"btech",3,54965416535,"[email protected]","cspc5",19,21),
(12112106,"monu",'M',"btech",3,54965416535,"[email protected]","cspc7",17,29),
(12112107,"monu2",'M',"btech",3,54965416535,"[email protected]","cspc7",17,29);
insert into students
values(110017,"Stripathi",'M',"Btech",3,8708934662,"[email protected]","cspc6",17,5);
insert into students
values(110018,"Sachin",'M',"Btech",3,8708934662,"[email protected]","cspc6",16,8);
insert into students
values(110020,"Suresh",'M',"Btech",3,8704634662,"[email protected]","cspc1",16,8);
Queries :
1.Update details of the guide of the student whose Roll-no is ‘110011’. The details of the new guide
are as Guide-name =‘Ram Mohan’ & Guide-No = ‘11’.
update students
set guide_no = 11,project_no = 26
where roll_number = 110011;
2.Remove Guide details where Guide-No is ‘15’ and assign a new guide with Guide-No '10' to all the
students who were earlier assigned to the guide with Guide-No '15'.
update project as p
set p.guide_no = 10
where project_no in (select project_no from students where guide_no=15);
update students
set guide_no=10
where guide_no=15;
3.Get a list of guides who are guiding more than two groups of students.
select *
from guide
where guide_no in (select guide_nofrom students
group by guide_no having count(distinct group_code) > 2);
Output:
4.Get a list of Project-No, Project-title, and names of guides who are guiding projects in the Project
area 'Database'.
select project_no,project_title,guide_name
from project natural join guide
where project_area = "dbms" and project_area = guide_research_area;
Output:
5. Get title of the Project-No ‘5’.
select project_title
from project
where project_no = 5;
Output:
(6). Get names of all the students of the project no. ‘5’.
select s_name
from students
where project_no = 5;
Output:
(7). List all the projects being guided by ‘Dr. S K Jain’.
select project_no,project_title,project_year_month
from project natural join guide
where guide_name = "SK jain";
(8). Get names of all the students being guided by ‘Dr. S K Jain’.
select s_name
from students
where guide_no in (select guide_nofrom guide where guide_name = "SK jain");
(9). List all the projects completed on ‘June
select *
from project
where project_year_month like '%201906%';
(10). List all the projects completed in year ‘2019’.
select *
from project
where project_year_month like '%2019%';
(11). Lists roll numbers and names of all the students who have their projects in Project area
“Programming”.
select s_name,roll_number
from students natural join project
where project_area = "programming";
(12). List names of all the teachers who are guiding projects to the students in the Project area
“Network”.
select distinct guide_name
from guide natural join project
where project_area = "networking";
(13). List names of all the students who have their projects in the Project area “Artificial
Intelligence”.
select s_name
from students natural join project
where project_area = "ai";
(14). List names of the guides with their Project areas.
select distinct project_area,guide_name
from project natural join guide;
15). Whether Project-No ‘7’ was guided by ‘Dr. S K Jain’ in ‘Dec 2020’.
select *
from project
where project_year_month like '%202012%' and guide_no in(select guide_no
from guide
where guide_name = "SK jain");
(16). List names of the students of the groups code ‘cspc3’.
select *
from students natural join groupss
where group_code = "cspc3";
(17). Retrieve name of the guide of the group ‘cspc5’.
select guide_name
from guide
where guide_no in (select guide_no
from students
where group_code = "cspc5");
(18). Retrieve group-codes of the students whose guide is ‘Dr. S K Jain’.
select group_code
from students
where guide_no in( select guide_no from guide where guide_name = "SK jain");
Exp4:
Using SQL statements, compute the following join operations on the above tables Employee and
Department:
1. Cartesian product
2. Natural join
3. Left outer join
4. Right outer join
5. Full outer join
6. Left semi-join
7. Right semi-join
Code:
create database Experiment4;
use experiment4;
create table Employee
(employee_id int primary key,
name_e varchar(45),
dept_name varchar(45) ,
foreign key (dept_name)references department(dept_name));
describe Employee;
create table department
(dept_name varchar(45) primary key,
manager varchar(30));
insert into department
values("sales","ram"),
("finance","reeta"),
("accounts","rohit"),
("office","mohit"),
("inventory","rohan");
insert into Employee
values(1101,"ramesh","sales"),
(2241,"suresh","finance"),
(2242,"kamal","sales"),
(2243,"ankur","inventory"),
(2245,"vikas","office"),
(2246,"sumit","sales");
update Employee
set dept_name = "accounts"
where employee_id = 2242;
insert into department
values("health","tripathi"),
("technology","shashank"),
("financial advisor","akshat");
--1. cartesian product
select *
from employee join department;
--2. natural join
select *from employee natural join department;
-- 3. left outer join
select *from department left join employee
on employee.dept_name = department.dept_name;
-- 4. right outer join
select *
from department right join employee
on employee.dept_name = department.dept_name;
-- 5. full outer join
( select *from department left join employee
on employee.dept_name = department.dept_name)union
(select *from department right join employee on employee.dept_name = department.dept_name);
-- 6. left semi join
select dept_name, manager
from department natural join employee;
-- 7. right semi join
select dept_name,employee_id,name_e
from department natural join employee;
EXPERIMENT UNIVERSITY DATABASE:
CLASSROOM (Building, Room-Number, capacity)
DEPARTMENT (Dept-name, building, budget)
COURSE (Course-id, title, dept-name, credits)
INSTRUCTER (I-ID, name, dept-name, salary)
STUDENT (S-ID, name, dept-name, tot-credit, I-ID)
TIME-SLOT (Time-slot-id, day, start-time, end-time)
SECTION (Course-id, sec-id, semester, year, building, room-number, Time-slot-id, day, start-time)
TEACHES (I-ID, Course-id, sec-id, semester, year)
TAKES (S-ID, Course-id, sec-id, semester, year, grade)
PREREQ (Course-id, Prereq-id)
Code:
create database university_database;
use university_database;
create table time_slot
(time_id int ,
day varchar(12) ,
start_time varchar(5) check(start_time like "__:__"),
end_time varchar(5) check (end_time like "__:__"),
primary key (time_id,day,start_time)
);
create table section
(course_id varchar(10),
sec_id varchar(10),
sem int,
year int ,
building varchar(45),
room_no varchar(10),
time_slot_id int,
day varchar(12),
start_time varchar(5),
primary key(course_id,sec_id,sem,year)
);
create table deaprtment
(dept_name varchar(20) primary key,
building varchar(25),
budget int );
create table teaches
(i_id int ,
course_id varchar(10),
sec_id varchar(10),
sem int ,
year int,
primary key (i_id,course_id,sec_id,sem,year));
create table takes
(s_id int ,
course_id varchar(10),
sec_id varchar(10),
sem int ,
year int ,
grade char,
primary key (s_id,course_id,sec_id,sem,year)
);
create table course
(course_id varchar(10) primary key,
title varchar(15),
dept_name varchar (20),
credits int,
foreign key(dept_name)references deaprtment(dept_name));
create table instructor
(i_id int primary key,
name varchar(12),
dept_name varchar(20),
salary int,
foreign key (dept_name)references deaprtment(dept_name));
create table student
(s_id int primary key,
name varchar(20),
dept_name varchar(20),
tot_cred int ,
i_id int ,
foreign key(dept_name)references deaprtment(dept_name),
foreign key(i_id)references instructor(i_id));
create table prereq
(course_id varchar(10),
prereq_id varchar(10),
primary key(course_id,prereq_id),
foreign key (course_id) references course(course_id),
foreign key (prereq_id) references course(course_id));
create table classroom
(building varchar(45),
room_no varchar(10),
capacity int ,
primary key (building,room_no));
-- data for classroom
insert into classroom
values("lecture hall complex","LHC-101",100),
("lecture hall complex","LHC-106",100),
("lecture hall complex","LHC-102",100),
("lecture hall complex","LHC-103",100),
("lecture hall complex","LHC-104",100),
("lecture hall complex","LHC-105",100),
("lecture hall complex","LHC-201",100),
("lecture hall complex","LHC-202",100),
("lecture hall complex","LHC-204",100),
("lecture hall complex","LHC-206",100),
("Electrical department","E-101",85),
("Electrical department","E-102",85),
("Electrical department","E-201",85),
("Electrical department","E-202",85),
("Electrical department","E-301",85),
("L-Block","L-1",85),
("L-Block","L-2",85),
("L-Block","L-3",85),
("L-Block","L-4",85),
("L-Block","L-5",85);
-- data for department
insert into deaprtment
values("Computer","Computer",25000),
("IT","Computer",20000),
("ECE","L-Block",25000),
("Electrical","Electrical",20000),
("Civil","AB-Block",25000),
("Mechnical","Applied Mechanics",20000),
("PIE","AB-Block",20000);
insert into deaprtment
values("lecture","Lecture Hall complex",50000);
-- data for courses
insert into course
values("cspc-11","daa","computer",3),
("cspc-12","java","computer",3),
("cspc-13","web-d","computer",3),
("cspc-14","c++","computer",3),
("cspc-15","c","computer",3),
("cspc-16","dsa","computer",3),
("itpc-12","java","computer",3),
("itpc-13","web-d","computer",3),
("itpc-14","c++","computer",3),
("itpc-15","c","computer",3),
("itpc-16","dsa","computer",3);
insert into course
values("itpc-20","dbms","IT",3),
("itpc-25","os","IT",3);
insert into course
values("cspc-46","computerNetwork","computer",4);
insert into course
values("cspc-47","cLanguages","computer",4);
-- data for instructor
insert into instructor
values(11,"JK CHABRA","Computer",150000),
(12,"Mayank dave","Computer",140000),
(13,"AK singh","Computer",160000),
(21,"Vijay verma","Computer",100000),
(22,"Mukesh kumar","ECE",100000),
(41,"PrashadJoshi","Mechnical",150000),
(56,"GauravMathur","Civil",140000);
insert into instructor
values(95,"Mohan majee","IT",90000);
-- data for student
insert into student
values(100,"rohan","computer",125,11),
(101,"Stripathi","computer",102,12),
(103,"Akshat","Mechnical",65,41),
(105,"Shashank","computer",95,11),
(157,"Sanyam","ECE",110,22),
(574,"pDubey","computer",99,11),
(952,"Samraat","computer",100,21),
(735,"chanks","IT",112,13);
insert into student
values(562,"rajKumari","IT",75,22);
-- data for time slot
insert into time_slot
values(1,"Monday","08:30","09:25"),
(2,"Monday","09:30","10:25"),
(3,"Monday","10:30","11:25"),
(4,"Monday","11:30","12:25"),
(5,"Monday","12:30","13:25"),
(1,"Tuesday","08:30","09:25"),
(3,"Tuesday","12:30","13:25"),
(5,"Tuesday","08:30","09:25"),
(1,"Friday","08:30","09:25"),
(2,"Friday","09:30","10:25"),
(4,"Friday","11:30","12:25"),
(1,"Saturday","08:30","09:25"),
(2,"Saturday","09:30","10:25"),
(4,"Saturday","11:30","12:25");
-- data for section
insert into section
values("cspc-11","cs-a",3,2,"lecture hall complex","LHC-101",1,"Monday","08:30"),
("cspc-12","cs-a",3,2,"lecture hall complex","LHC-101",2,"Monday","09:30"),
("cspc-16","cs-a",3,2,"lecture hall complex","LHC-101",3,"Friday","10:30"),
("cspc-14","cs-b",3,2,"lecture hall complex","LHC-102",2,"Monday","09:30"),
("cspc-13","cs-b",3,2,"lecture hall complex","LHC-103",3,"Monday","10:30"),
("cspc-15","cs-b",3,2,"lecture hall complex","LHC-103",4,"Tuesday","11:30"),
("cspc-13","cs-c",3,2,"lecture hall complex","LHC-105",2,"Tuesday","10:30"),
("cspc-12","cs-c",3,2,"lecture hall complex","LHC-105",3,"Tuesday","11:30"),
("cspc-16","cs-c",3,2,"lecture hall complex","LHC-104",5,"Saturday","13:30"),
("itpc-11","it-a",3,2,"L-Block","L-1",1,"Monday","08:30"),
("itpc-13","it-a",3,2,"Electrical department","E-101",3,"Saturday","10:30"),
("itpc-11","it-b",3,2,"L-Block","L-5",2,"Tuesday","09:30"),
("itpc-12","it-b",3,2,"Electrical department","E-201",5,"Friday","13:30");
-- data for teaches
insert into teaches
values(11,"cspc-14","cs-b",3,2),
(11,"cspc-11","cs-a",3,2),
(12,"cspc-12","cs-a",3,2),
(13,"cspc-13","cs-b",3,2),
(12,"cspc-12","cs-c",3,2),
(21,"itpc-11","it-b",3,2),
(13,"itpc-13","it-a",3,2),
(11,"itpc-12","it-b",3,2);
insert into teaches
values(22,"cspc-47","cs-b",3,2);
-- data for takes
insert into takes
values
(100,"cspc-13","cs-b",3,2,"A"),
(100,"cspc-14","cs-b",3,2,"A"),
(100,"cspc-15","cs-b",3,2,"A"),
(101,"cspc-16","cs-a",3,2,"B"),
(101,"cspc-11","cs-a",3,2,"A"),
(105,"cspc-12","cs-c",3,2,"B"),
(105,"cspc-13","cs-c",3,2,"C"),
(105,"cspc-16","cs-c",3,2,"B"),
(735,"itpc-11","it-a",3,2,"B"),
(735,"itpc-13","it-a",3,2,"B");
-- data for prereq
insert into prereq
values
("cspc-11","cspc-15"),
("cspc-16","cspc-15"),
("itpc-16","itpc-15"),
("cspc-12","cspc-14");
Exp5:
-- 1.Increase Salary by 20 percent of all instructors who are working in Department IT.
update instructor
set salary = salary +(salary*0.20)
where dept_name = "IT";
select salary
from instructor
where dept_name = "IT";
-- 2. Retrieve names of all instructors along with their department names
select name,dept_name
from instructor;
-- 3.Retrieve names of all instructors along with their department names and building names in
which the departments are housed.
select i.name,i.dept_name,d.building
from instructor as i natural join deaprtment as d;
-- 4.Retrieve names of all departments along with names of the buildings in which they are situated.
select dept_name,building
from deaprtment;
-- 5. Change name of the building "Lecture Hall Complex" to "Lecture Theatre Complex".
update classroom
set building = "Lecture Theatre Complex"
where building = "lecture hall complex";
-- 6. Find name of the department of a student with ID _____. (Take a valid ID value of a student)
select name
from student
where s_id = 100;
-- 7. Retrieve names of all instructors along with the Course IDs of the courses they teach.
select i.name,c.course_id
from instructor as i natural join teaches as c;
-- 8. Retrieve Course ID, semester, year and title of each course being taught by "Computer Engg."
department.
select t.course_id,t.sem,t.year,c.title
from course as c natural join teaches as t
where c.dept_name = "computer";
-- 9. Compute monthly salary of all instructors and display it as 'monthly salary' attribute in place of
attribute 'salary'.
select name,salary as monthly_salary
from instructor;
-- 10. Retrieve names of all departments housed in the building named _______. (Consider a valid
Building name)
select dept_name
from deaprtment
where building = "computer";
-- 11. Find the names of all instructors belonging to Computer Engg. department who have salary
greater than Rs. 70,000.
select name,salary
from instructor
where dept_name = "computer" and salary > 70000;
-- 12. Find titles of the courses that have credits 3 and offered by the department IT.
select title
from course
where credits = 3 and dept_name = "IT";
-- 13. Find course names and their credits running in semester 3.
select c.title,c.credits
from course as c natural join section as t
where t.sem = 3;
-- 14. List classes as year and semester wise engaged in room no. LHC-102.
select year,sem,course_id
from section
where room_no = "LHC-102";
-- 15. List classes as year, semester and section wise engaged in room no. LHC-102
select year,sem,course_id,sec_id
from section where room_no = "LHC-102";
-- 16. List classes as year, semester and section wise engaged in room no. LHC-101.
select year,sem,course_id,sec_id from section where room_no = "LHC-101";
-- 17. Retrieve list of room number & time slot where all classes of Computer Engg.. Semester 3rd
are scheduled.
select s.room_no,s.time_slot_id from section as s natural join (student natural join takes)
where dept_name = "computer" and sem = 3;
-- 18. Retrieve Course titles taught by instructor _______. (Take a valid instructor ID or name)
select title
from course
where course_id =ANY (select course_id from instructor natural join teaches where i_id = 11);
-- 19. For all instructors in the university who have taught some course, display their names along
with their department names.
select distinct i.name,i.dept_name
from instructor as i natural join teaches;
-- 20. Find the names of all instructors who have a higher salary than some instructor in "Computer
Engg." department.
select name
from instructor
where salary > (select salary from instructor where i_id = 95);
Exp6:
Write the following queries in the SQL for the above-mentioned database of a university.
string operation, between, Aggregate, group by
(1). Find names of all departments whose building name includes the substring “Hall”.
(2). Find names of all instructors who have their salaries between Rs.
40,0000 and Rs. 50,0000.
(3). Find names of all students whose names begin with string "Sa":
(4). Find names of all students belonging to Computer Engg. department and
their names
begin with character "Sa":
(5). Retrieve list of courses taught by teachers whose names begin with
character "S".
(6). Retrieve list of courses beginning their titles with word "o".
(7). Retrieve list of courses containing the word "fa" in their titles.
(8). Retrieve names of the instructors who teach courses containing word
"language" in their titles.
(9). Find IDs of all students whose names include "an" and their department
is IT.
(10). Find average salary of all instructors.
(11). Find average salary of the instructors belonging to Computer Engg, department.
(12). Find average salary of the instructors belonging to each department.
(13). Find names and average salaries of all departments whose average
salary is greater than Rs. 400000.
(14). Find total number of courses offered by the university.
(15). Find total number of courses offered by the Computer Engg department.
(16). Find total number of courses taught in the 3rd semester 2018.
(17). Find total number of instructors who teach a course in the 3rd semester 2018.
(18). Find maximum salary of an instructor belonging to Computer Engg, department.
(19). Find minimum salary of an instructor belonging to Computer Engg, department.
(20). Find maximum salary of an instructor in the university.
(21). Find total number of students enrolled in the university
(22). Find total number of students enrolled in each department of the university.
(24). Find instructors whose average salaries are greater than that of the instructors belonging to the
'computer engg' department.
(25). Retrieve total no. of students in each department who earned total credits more than 9.7.