Question

In: Computer Science

Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-

Consider the following relational database schema:

            employee(employee-name, employee-id, street, e-city)

            works(employee-id, company-id, salary)

            company(company-name, company-id, c-city)

            manages(employee-id, manager-id)

Specify the following queries on this database schema using the relational operators we discussed in class. Write your answers on a separate sheet of paper in the order that they are specified below.

  1. Retrieve the name and address of employees who work for First Bank Corporation.
  1. Retrieve the name, street address, and city of residence of all employees who work for Thrifty Industries and earn more than $10,000 per year.

  1. Retrieve the name of all employees who live in the same city as the company for which they work.

  1. Retrieve the name of all employees who live on the same street and in the same city as do their managers.

  1. Retrieve the name of all employees who do not work for First Bank Corporation.

  1. Retrieve the name of all employees who earn more than every employee of Small Bank Corporation.

  1. (Assume that companies may be located in several cities) Retrieve all companies located in every city in which Thrifty Industries is located.

  1. For each company, find the average salary of employees working for that company.

  1. For each city, find the number of employees who work for at least one company in that city.

Solutions

Expert Solution

  1. Retrieve the name and address of emplofyees who work for First Bank Corporation
    SELECT employee_name , street, e-city FROM employee WHERE comapany-name IN (SELECT company-name FROM company WHERE company-name ="First Bank Corporation")
  2. Retrieve the name, street address, and city of residence of all employees who work for Thrifty Industries and earn more than $10,000 per year
    SELECT E.employee-name, street,city FROM employee as E, works as W where E.employee-name = W.employee-name and W.company-name = 'Thrifty Industries' AND salary > 10000
  3. Retrieve the name of all employees who live in the same city as the company for which they work.
    SELECT E.employee-name from employee as E, works as W , Company as C where E.employee-name = W.employee-name and E.city = C.city and W.company-name = C.company-name
  4. Retrieve the name of all employees who live on the same street and in the same city as do their managers.
    SELECT E1.employee-name From employee as E1, Employee as E2, Manages as M WHERE E1.employee-id = M.employee-id and E2.employee-id = M.manager-id AND E1.street = E2.street AND E1.city = E2.city
  5. Retrieve the name of all employees who do not work for First Bank Corporation.
    SELECT employee-name FROM employee WHERE company-name IN (SELECT company-name FROM Works WHERE company-name != 'First Bank Corporation'
  6. Retrieve the name of all employees who earn more than every employee of Small Bank Corporation.
    SELECT employee-name FROM employee WHERE salary > ( SELECT salary FROM works WHERE company-name = 'Small Bank Corporation')
  7. Retrieve all companies located in every city in which Thrifty Industries is located.
    SELECT C.company-name FROM company C WHERE ( SELECT R.city FROM company R WHERE R.company-name = T.company-name) CONTAINS (SELECT S.city FROM company S WHERE S.company-name = 'Thrifty Industries')
  8. For each company, find the average salary of employees working for that company.
    SELECT company-name FROM company GROUP BY company-name HAVING  AVG(salary) FROM works

Related Solutions

• Relational Schema Create a relational database schema consisting of the four relation schemas representing various...
• Relational Schema Create a relational database schema consisting of the four relation schemas representing various entities recorded by a furniture company.   Write CREATE TABLE statements for the following four relation schemas. Define all necessary attributes, domains, and primary and foreign keys. Customer(CustomerID, Name, Address) FullOrder(OrderID, OrderDate, CustomerID) Request(OrderID, ProductID, Quantity) Product(ProductID, Description, Finish, Price) You should assume the following: Each CustomerID is a number with at most three digits, each OrderID is a number with at most five digits,...
Question 2: consider the following library relational database schema Write a program segment to retrieves the...
Question 2: consider the following library relational database schema Write a program segment to retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each. 1- Use JDBC with Java as the host language
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street,...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street, city, state, zip, card_type, card_no, expiration, name_on_card) book_SALE(listing_no, seller, isbn, condition, price) ORDERS(order_no, buyer, order_date, tot) ITEM(order_no, listing_no) BOOK(isbn, title, author, edition, publisher, keywords) The bold attribute(s) in a relation is the primary key of that relation. The italized attributes in some relations denote foreign keys. The seller attribute in the book_SALE relation is a foreign key to the user attribute in the MEMBER...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street,...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street, city, state, zip, card_type, card_no, expiration, name_on_card) book_SALE(listing_no, seller, isbn, condition, price) ORDERS(order_no, buyer, order_date, tot) ITEMS(order_no, listing_no) BOOK(isbn, title, author, edition, publisher, keywords) The bold attribute(s) in a relation is the primary key of that relation. The italized attributes in some relations denote foreign keys. Create/Define the table.
The following tables form part of a database (Flights Database) held in a relational DBMS: employee...
The following tables form part of a database (Flights Database) held in a relational DBMS: employee (empNo, empName, empSalary, empPosition) aircraft (aircraftNo, acName, acModel, acFlyingRange) flight (flightNo, aircraftNo, fromAirport, toAirport, flightDistance, departTime, arriveTime) certified (empNo, aircraftNo) Where:  employee contains details of all employees (pilots and non-pilots) and empNo is the primary key;  aircraft contains details of aircraft and C is the primary key.  flight contains details of flights and (flightNo, aircraftNo) form the primary key.  certified...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition,...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition, price), PK: ISBN, FK: published_by refs Publisher, previous_edition refs Book. Author (SSN, first_name, last_name, address, income), PK: SSN. Write (aSSN, bISBN), PK: (aSSN, bISBN), FK: aSSN refs Author, bISBN refs Book. Editor (SSN, first_name, last_name, address, salary, works_for, book_count), PK: SSN, FK: works_for refs Publisher. Edit (eSSN, bISBN), PK: (eSSN, bISBN), FK: eSSN refs Editor, bISBN refs Book. Author_Editor (aeSSN, hours), PK: aeSSN, FK:...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition,...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition, price), PK: ISBN, FK: published_by refs Publisher, previous_edition refs Book. Author (SSN, first_name, last_name, address, income), PK: SSN. Write (aSSN, bISBN), PK: (aSSN, bISBN), FK: aSSN refs Author, bISBN refs Book. Editor (SSN, first_name, last_name, address, salary, works_for, book_count), PK: SSN, FK: works_for refs Publisher. Edit (eSSN, bISBN), PK: (eSSN, bISBN), FK: eSSN refs Editor, bISBN refs Book. Author_Editor (aeSSN, hours), PK: aeSSN, FK:...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys are italic) STUDENT(StudentID, name, major, year, age) CLASS(ClassName, meetsAt, room, LecturerID) ENROLLED(StudentID, ClassName, mark) LECTURER(LecturerID, name, DepartmentID) DEPARTMENT(DepartmentID, name) Write the SQL statements for the following query: B1. Find the age of the oldest student. B2. Find the ID’s of lecturers whose name begins with “K” \ B3. Find the age of the youngest student who is enrolled in Mechatronics. B4. Find the age...
What is Relational Database in healthcare? Provide examples and explain how it works.
What is Relational Database in healthcare? Provide examples and explain how it works.
List department name, employee id, and employee name for all employees in department name order. Repeat...
List department name, employee id, and employee name for all employees in department name order. Repeat for department #10 only. List the course ID, course name, section, instructor name, day, time, and room for all course sections. List the course ID, course name, section, student ID, and student name for CRN 1003. Display the list in ascending order of student last and first names. DROP TABLE registration; DROP TABLE sections; DROP TABLE courses; DROP TABLE students; DROP TABLE instructors; CREATE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT