Download presentation
Presentation is loading. Please wait.
Published byClaud Barber Modified over 9 years ago
1
1Database Management Systems Exercise II Consider the following relational schemas: employee (person_name, street, city) company (company_name, city) works (person_name, company_name, salary) manages (person_name, manager_name)
2
2Database Management Systems Q1: Find the names of employees who work for some company in Boston. person_name (works city = “Boston” (company)) selectdistinct w.person_name fromworks w, company c wherew.company_name = c.company_name andc.city = “Boston”
3
3Database Management Systems Q2: Find the streets of employees who work for all companies in Boston. street (employee ( person_name, company_name (works) company_name ( city = “Boston” (company)))) select distinct e.street from employee e, works w where e.person_name = w. person_name and not exists ((select company_name from company where city = “Boston”) except (select company_name from works w1 where w1.person_name = w.person_name))
4
4Database Management Systems Q3: Find the names of all managers who earn more than $10,000. person_name ( salary > 10000 (works)) manager_name (manages) select distinct w.person_name from works w, manages m where w.person_name = m.manager_name and w.salary > 10000
5
5Database Management Systems Q4: Find the names and cities of employees who work for First Bank Corporation and earn more than $10,000. person_name, city (employee ( salary > 10000 company_name = “First Bank Corporation” (works))) select person_name, city from employee where person_name in (select person_name from works where salary > 10000 and company_name = “First Bank Corporation”)
6
6Database Management Systems Q5: Find the names of managers who manage all employees working for First Bank Corporation. manager_name, person_name (manages) person_name ( company_name = “First Bank Corporation” (works)) select m.manager_name from manages m where not exists ((select person_name from works where company_name = “First Bank Corporation”) except (select m2.person_name from manages m2 where m.manager_name = m2.manager_name))
7
7Database Management Systems Find the names of the employees whose salaries are higher than those of all employees living in Los Angeles. (One employee may have several works.)
8
8Database Management Systems Find the names of the managers whose salaries are higher than that of at least one employee that they manage. (One employee may have several works.)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.