University
University
University
Course (course-id, title, dept-name, credits) Instructor (ID, name, depart-name, salary) Section (course-id, sec-id, semester, year, building, room-number, time-slot-id) Teaches (ID, course-id, sec-id, semester, year) Student (ID, name, dept-name, tot-cred) Takes (ID, course-id, sec-id, semester, year, grade) Advisor (s-ID, i-ID) Time-slot (time-slot-id, day, start-time, end-time) Prereq (course-id, prereq-id)
insert insert insert insert insert insert insert insert insert insert insert insert insert
into into into into into into into into into into into into into
time_slot time_slot time_slot time_slot time_slot time_slot time_slot time_slot time_slot time_slot time_slot time_slot time_slot
values values values values values values values values values values values values values
( ( ( ( ( ( ( ( ( ( ( ( (
'A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'D', 'D', 'D', 'E',
'M', 'W', 'F', 'M', 'W', 'F', 'M', 'W', 'F', 'M', 'W', 'F', 'T',
8, 0, 8, 50); 8, 0, 8, 50); 8, 0, 8, 50); 9, 0, 9, 50); 9, 0, 9, 50); 9, 0, 9, 50); 11, 0, 11, 50); 11, 0, 11, 50); 11, 0, 11, 50); 13, 0, 13, 50); 13, 0, 13, 50); 13, 0, 13, 50); 10, 30, 11, 45);
insert insert insert insert insert insert insert insert insert insert insert insert insert insert insert
into into into into into into into into into into into into into into into
classroom classroom classroom classroom classroom classroom classroom classroom classroom classroom classroom classroom classroom classroom classroom
values('Lamberton', 134, 10); values('Chandler', 375, 10); values('Fairchild', 145, 27); values('Nassau', 45, 92); values('Grace', 40, 34); values('Whitman', 134, 120); values('Lamberton', 143, 10); values('Taylor', 812, 115); values('Saucon', 113, 109); values('Painter', 86, 97); values('Alumni', 547, 26); values('Alumni', 143, 47); values('Drown', 757, 18); values('Saucon', 180, 15); values('Whitman', 434, 32);
insert insert insert insert insert insert insert insert insert insert insert insert insert insert insert
into into into into into into into into into into into into into into into
department department department department department department department department department department department department department department department
values('Civil Eng.', 'Chandler', 255041.46); values('Biology', 'Candlestick', 647610.55); values('History', 'Taylor', 699140.86); values('Physics', 'Wrigley', 942162.76); values('Marketing', 'Lambeau', 210627.58); values('Pol. Sci.', 'Whitman', 573745.09); values('English', 'Palmer', 611042.66); values('Accounting', 'Saucon', 441840.92); values('Comp. Sci.', 'Lamberton', 106378.69); values('Languages', 'Linderman', 601283.60); values('Finance', 'Candlestick', 866831.75); values('Geology', 'Palmer', 406557.93); values('Cybernetics', 'Mercer', 794541.46); values('Astronomy', 'Taylor', 617253.94); values('Athletics', 'Bronfman', 734550.70);
insert insert insert insert insert insert insert insert insert insert insert
into into into into into into into into into into into
course course course course course course course course course course course
values('787', values('238', values('608', values('539', values('278', values('972', values('391', values('814', values('272', values('612', values('959',
'C Programming', 'Mech. Eng.', 4); 'The Music of Donovan', 'Mech. Eng.', 3); 'Electron Microscopy', 'Mech. Eng.', 3); 'International Finance', 'Comp. Sci.', 3); 'Greek Tragedy', 'Statistics', 4); 'Greek Tragedy', 'Psychology', 4); 'Virology', 'Biology', 3); 'Compiler Design', 'Elec. Eng.', 3); 'Geology', 'Mech. Eng.', 3); 'Mobile Computing', 'Physics', 3); 'Bacteriology', 'Physics', 4);
insert into course values('237', 'Surfing', 'Cybernetics', 3); insert into course values('313', 'International Trade', 'Marketing', 3); insert into course values('887', 'Latin', 'Mech. Eng.', 3);
insert into 32570.50); insert into insert into insert into insert into insert into insert into insert into insert into 62579.61); insert into insert into
instructor values('50885', 'Konstantinides', 'Languages', instructor instructor instructor instructor instructor instructor instructor instructor values('79653', values('50330', values('80759', values('73623', values('97302', values('57180', values('74420', values('35579', 'Levine', 'Elec. Eng.', 89805.83); 'Shuming', 'Physics', 108011.81); 'Queiroz', 'Biology', 45538.32); 'Sullivan', 'Elec. Eng.', 90038.09); 'Bertolino', 'Mech. Eng.', 51647.57); 'Hau', 'Accounting', 43966.29); 'Voronina', 'Physics', 121141.99); 'Soisalon-Soininen', 'Psychology',
instructor values('31955', 'Moreira', 'Accounting', 71351.42); instructor values('34175', 'Bondi', 'Comp. Sci.', 115469.11);
insert into section values('313', '1', 'Fall', 2010, 'Chandler', '804', 'N'); insert into section values('747', '1', 'Spring', 2004, 'Gates', '314', 'K'); insert into section values('443', '1', 'Spring', 2010, 'Whitman', '434', 'O');
insert 'B'); insert 'D'); insert insert insert 'J'); insert insert insert insert 'G');
into section values('893', '1', 'Fall', 2007, 'Fairchild', '145', into section values('663', '1', 'Spring', 2005, 'Fairchild', '145', into section values('457', '1', 'Spring', 2001, 'Saucon', '844', 'D'); into section values('445', '1', 'Spring', 2001, 'Alumni', '547', 'J'); into section values('559', '1', 'Fall', 2002, 'Lamberton', '134', into into into into section section section section values('239', values('735', values('959', values('612', '1', '1', '1', '1', 'Fall', 2006, 'Taylor', '183', 'C'); 'Spring', 2003, 'Drown', '757', 'D'); 'Fall', 2006, 'Saucon', '180', 'M'); 'Fall', 2007, 'Lamberton', '143',
insert insert insert insert insert insert insert insert insert insert insert
into into into into into into into into into into into
teaches teaches teaches teaches teaches teaches teaches teaches teaches teaches teaches
values('63395', '747', '1', 'Spring', 2004); values('3199', '169', '1', 'Spring', 2007); values('6569', '445', '1', 'Spring', 2001); values('28097', '808', '1', 'Fall', 2003); values('22591', '962', '1', 'Spring', 2008); values('90376', '158', '1', 'Fall', 2008); values('3199', '561', '1', 'Fall', 2006); values('34175', '274', '1', 'Fall', 2002); values('34175', '571', '1', 'Spring', 2004); values('79081', '345', '1', 'Spring', 2008); values('74420', '443', '2', 'Spring', 2002);
Optional
insert insert insert insert insert insert insert insert insert insert insert insert insert insert insert into into into into into into into into into into into into into into into student student student student student student student student student student student student student student student values('24746', values('79352', values('76672', values('14182', values('44985', values('96052', values('35175', values('44271', values('40897', values('92839', values('79329', values('97101', values('24865', values('36052', values('98940', 'Schrefl', 'History', 4); 'Rumat', 'Finance', 100); 'Miliko', 'Statistics', 116); 'Moszkowski', 'Civil Eng.', 73); 'Prieto', 'Biology', 91); 'Marcol', 'Cybernetics', 15); 'Quimby', 'History', 4); 'Sowerby', 'English', 108); 'Coppens', 'Math', 58); 'Cirsto', 'Math', 115); 'Velikovs', 'Marketing', 110); 'Marek', 'Psychology', 53); 'Tran-', 'Marketing', 116); 'Guerra', 'Elec. Eng.', 59); 'Hawthorne', 'Marketing', 78);
insert into takes values('65901', '401', '1', 'Fall', 2003, 'C-'); insert into takes values('24932', '802', '1', 'Spring', 2003, 'B-');
insert insert insert insert insert insert insert insert insert insert insert insert insert
into into into into into into into into into into into into into
takes takes takes takes takes takes takes takes takes takes takes takes takes
values('61332', '200', '1', 'Spring', 2007, 'A-'); values('73492', '760', '1', 'Spring', 2004, 'A '); values('65715', '843', '1', 'Fall', 2010, 'B+'); values('58300', '408', '1', 'Spring', 2007, 'B-'); values('760', '571', '1', 'Spring', 2004, 'B '); values('69730', '313', '1', 'Fall', 2010, 'A '); values('94836', '626', '1', 'Fall', 2006, 'C+'); values('49391', '603', '1', 'Fall', 2003, 'B-'); values('48850', '457', '1', 'Spring', 2001, 'C-'); values('68999', '169', '1', 'Spring', 2007, 'A+'); values('53469', '169', '1', 'Spring', 2007, 'C '); values('74016', '747', '1', 'Spring', 2004, 'A-'); values('49073', '496', '1', 'Fall', 2001, 'C-');
insert insert insert insert insert insert insert insert insert insert
into into into into into into into into into into
advisor advisor advisor advisor advisor advisor advisor advisor advisor advisor
values('24746', values('79352', values('76672', values('14182', values('44985', values('96052', values('35175', values('44271', values('40897', values('92839',
'19368'); '95030'); '22591'); '77346'); '31955'); '73623'); '90643'); '58558'); '73623'); '25946');
insert insert insert insert insert insert insert insert insert insert
into into into into into into into into into into
prereq prereq prereq prereq prereq prereq prereq prereq prereq prereq
values('376', values('760', values('403', values('353', values('629', values('608', values('158', values('496', values('241', values('958',
'130'); '169'); '345'); '647'); '139'); '864'); '408'); '489'); '486'); '969');
1.-- Find the names of all instructors. select name from instructor;
2.-- Find the department names of all instructors. selectdept_name from instructor;
3.-- Find the name and the department names of all instructors. select name, dept_name from instructor;
4-- Find the ID, name, the department names and salary of all instructors. select ID, name, dept_name, salary from instructor;
6.-- Use distinct keyword to remove duplicate tuples select distinct dept_name from instructor;
7.-- Use all keyword to retain duplicate tuples select all dept_name from instructor;
9.--Alias or rename operation -- Find instructor names and course identifiers that they teach select I.name, T.course_id from instructor as I, teaches as T where I.ID = T.ID;
10-- Find the names of all instructors in the Computer Science department who have salary greater than Rs. 70,000 select name from instructor where dept_name = 'Comp. Sci.' and salary > 70000;
11-- Retrieve the names of all instructors, along with their department names -- and department building name select name, instructor.dept_name, building from instructor, department where instructor.dept_name = department.dept_name
-- in the physics department select name, course_id from instructor, teaches where instructor.ID = teaches.ID and instructor.dept_name = 'physics';
13-- Find the names of all departments whose building name includes the substring man' Select dept_name from department where building like '%man%';
14-- List in alphabetic order all instructors in the Computer Science department Select name from instructor where dept_name = 'Accounting' order by name;
15-- Find the names of instructors with salary between $90,000 and $100,000 Select name from instructor where salary between 90000 and 100000;
16-- Find the total salary paid to instructors select sum(salary) from instructor;
17-- Find the total number of instructors who teach a course in the spring 2008 semester select count(distinct ID) from teaches where semester = 'Spring' and year = 2010;
18-- Find the average salary for each department selectdept_name, avg(salary) as avg_salary from instructor group by dept_name;
19-- Find the departments where the average salary of the instructors -- is more than RS. 42,000 selectdept_name, avg(salary) as avg_salary from instructor group by dept_name having avg(salary) > 42000;
20-- Find all the courses taught in the both the Fall 2008 and Spring 2001 semester select distinct course_id from section where semester = 'Fall' and year = 2008 and course_id in( selectcourse_id from section where semester = 'Spring'
--21 Find the names of all instructors whose salary is greater than at least one instructor -- in the Biology department select name, salary from instructor where salary > some ( select salary from instructor where dept_name = 'Biology' ) order by name;
--22 find the names of all instructors that have a salary value greater than that of each instructor in the Biology department select name, salary from instructor where salary > all ( select salary from instructor wheredept_name = 'Biology' ) order by name;
--23 Create a view that lists all course sections offered by the Physics department in Fall 2006 semester, with the building and room number of each section create view physics_fall_2006 as select course.course_id, sec_id, building, room_number from course, section where course.course_id = section.course_id and course.dept_name = 'Physics' and section.semester = 'Fall' and section.year = 2006;