0% found this document useful (0 votes)
37 views18 pages

P S T U: Atuakhali Cience AND Echnology Niversity

The document appears to be an assignment submission for a database systems course. It includes 14 queries written in SQL to solve various tasks, such as selecting data from tables based on conditions, aggregating data using functions, and performing set operations on query results. The queries select and analyze data from tables representing courses, instructors, departments and other database relations.

Uploaded by

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

P S T U: Atuakhali Cience AND Echnology Niversity

The document appears to be an assignment submission for a database systems course. It includes 14 queries written in SQL to solve various tasks, such as selecting data from tables based on conditions, aggregating data using functions, and performing set operations on query results. The queries select and analyze data from tables representing courses, instructors, departments and other database relations.

Uploaded by

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

PATUAKHALI SCIENCE AND TECHNOLOGY

UNIVERSITY
Faculty of Computer Science and Engineering

Assignment 02
Course Title: Database System Sessional
Course Code: CCE-224

Submitted to:
Dr. Md. Samsuzzaman
Professor
Department of Computer and Communication Engineering
Faculty of Computer Science and Engineering
Patuakhali Science and Technology University, Dumki, Patuakhali,
Bangladesh

Submitted by:
Name : Ruhit Shah
ID : 1802055
Reg : 08465
Solving all the queries:

select dept_name
from department
where building like '%Watson%';

select instructor.*
from instructor, teaches
where instructor.ID= teaches.ID;
select name
from instructor
where dept_name = 'Physics'
order by name;

select *
from instructor
order by salary desc, name asc;

select name
from instructor
where salary <= 100000 and salary
>= 90000;
(select course_id
from section
where semester = 'Fall' and year=
2017)
union
(select course_id
from section
where semester = 'Spring' and
year= 2018);

(select course_id
from section
where semester = 'Fall' and year=
2017)
union all
(select course_id
from section
where semester = 'Spring' and
year= 2018);

(select course_id
from section
where semester = 'Fall' and year=
2017)
intersect
(select course_id
from section
where semester = 'Spring' and
year= 2018);

(select course_id
from section
where semester = 'Fall' and year=
2017)
except
(select course_id
from section
where semester = 'Spring' and
year= 2018);

select avg (salary)


from instructor
where dept_name = 'Comp. Sci.';

select avg (salary) as avg_salary


from instructor
where dept_name = 'Comp. Sci.';

select COUNT(ID)
from teaches
where semester = 'Spring' and
year = 2018;

select count(*)
from course;

select avg (salary)


from instructor;

select dept_name, ID, avg


(salary)
from instructor
group by dept_name;
select dept_name, avg (salary) as
avg_salary
from instructor
group by dept_name
having avg (salary) > 42000;

select sum(salary)
from instructor;

(select course_id
from section
where semester = 'Spring' and year=
2018)
select distinct course_id
from section
where semester = 'Fall' and year=
2017 and
course_id in (select course_id
from section
where semester = 'Spring' and year=
2018);
select distinct course_id
from section
where semester = 'Fall' and year=
2017 and
course_id not in (select course_id
from section
where semester = 'Spring' and year=
2018);

select distinct name


from instructor
where name not in ('Mozart',
'Einstein');
select name
from instructor
where salary > some (select salary
from instructor
where dept_name = 'Biology');
select name
from instructor
where salary > all (select salary
from instructor
where dept_name = 'Biology');

select dept_name
from instructor
group by dept_name
having avg (salary) >= all (select
avg (salary)
from instructor
group by dept_name);
select course_id
from section as S
where semester = 'Fall' and year=
2017 and
exists (select *
from section as T
where semester = 'Spring' and year=
2018 and
S.course_id= T.course_id);

select T.course_id
from course as T
where 1 >= (select count(R.course_id)
from section as R
where T.course_id= R.course_id and
R.year = 2017);

with max_budget (value) as


(select max(budget)
from department)
select budget
from department, max_budget
where department.budget =
max_budget.value;
with dept_total (dept_name, value) as
(select dept_name, sum(salary)
from instructor
group by dept_name),
dept_total_avg(value) as
(select avg(value)
from dept_total)
select dept_name
from dept_total, dept_total_avg
where dept_total.value>
dept_total_avg.value;
select dept_name,
(select count(*)
from instructor
where department.dept_name =
instructor.dept_name)
as num_instructors
from department;

You might also like