Question

Relational algebra (RA) For the database schema shown below, write RA query for each of the...

Relational algebra (RA)

For the database schema shown below, write RA query for each of the following. (State any reasonable assumptions only if necessary)

employee (person_name, street, city)

works(person_name, company_name, salary)

company (company_name, city)

Questions:

  1. Find person names, streets and cities of employees who work for two different companies.
  2. For each company, find person name, salary, street and city for the highest paid employee of that company.
  3. For each company, find total number of employees and total number of cities their employees reside.
  4. Find name and city of the company which has highest-paid employee among employees from all companies, along with the name and salary of this employee.
  5. Find name and city of any company which has employees living in Lincoln and Omaha. [Meaning of the query: For each of these companies, it has some employees live in Lincoln, and some others live in Omaha. Note no employee can live in to different cities.]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:--------------

a.

b. cmm --> Πcompany_nameG max(salary) as s (works)
Result
--> ( Πcompany_name, person_name, salary(cmm |X| works |X| employee))

c. (ΠCompany_nameG count(person_name), count(distinct city)(works |X| employee)

d. (Πperson_name, salary((G max(salary) as maxS(works)) |X| works))|X| Company

e. The easiest way is to use divide and conquer: Write two subquries: “Find name and city of any company which has employees living in Lincoln” and “Find name and city of any company which has employees living in Omaha,” then take intersection.Note: If you write σemployee.city = ‘Lincoln’ employee.city = ‘Lincoln’… It will not work, because an employee can only live in one city, so the result is ALWAYS empty.
On the other hand, if you use the following to get company names, it does not guarantee correct answer, since companies with employees living in one of the two cities will also be returned:

σemployee.city = ‘Lincoln’ employee.city = ‘Lincoln’…

To remedy this problem, some students included post-processing steps: first project out employee city names for each company (which should return two tuples including names of both cities), then take the division. Another approach is to count the number of employee cities for each company, and return the number of company name if the count is equal to two. Both approach are OK but less straightforward.

Add a comment
Know the answer?
Add Answer to:
Relational algebra (RA) For the database schema shown below, write RA query for each of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • HELP DATABASE QU Question 1: Think About the relational database table data as given below, write...

    HELP DATABASE QU Question 1: Think About the relational database table data as given below, write the following queries in Oracle SQL. Company (Cid, Cname, City, Budget, Branch) Department (Deptno, Dname, Building, Cname) Employee (Ename, Deptno, Street, City, Phone, Salary) Works (Ename, Deptno, Hire_date) Location (Cname, Location ) 1. Write Query to Create the Company table, suggest appropriate data type of each attribute, consider that there should be a name for each company. 2. Find employee name/names who live in...

  • employee(employee-id, employee-name, street, city) works(employee-id, company-id, salary) company(company-id, company-name, city) manages(employee-id, manager-id) Consider the data base...

    employee(employee-id, employee-name, street, city) works(employee-id, company-id, salary) company(company-id, company-name, city) manages(employee-id, manager-id) Consider the data base above where the primary keys are in bold For each of the questions give the following. (NOTICE the Relations on the given database it isn't like the ones that are commonly posted they are slightly different) (1) a relational algebra expression, (2) a tuple relational calculus expression, and (3) a domain relational calculus expression. f. Find all employees in the database who do not...

  • Consider the following relational schema of the company’s database. Use Tuple Relational Calculus (TRC) & Domain...

    Consider the following relational schema of the company’s database. Use Tuple Relational Calculus (TRC) & Domain Relational Calculus (DRC) expression to answer each of the following three questions (Step by step brief description is appreciated if possible) PRODUCT (pid, stock, supplier) CLIENT (cid, name, address, city) ORDER (orderno, date, quantity, pid, cid) Question 1: Find the number of orders for products that are being ordered in quantities smaller than 100 items by customers living in Madrid. Provide solutions expressed both...

  • Consider the relational database schema for a company below. EMPLOYEE/NAME, SSN, BDATE, ADDRESS, SEX, SALARY, SUPERSSN,...

    Consider the relational database schema for a company below. EMPLOYEE/NAME, SSN, BDATE, ADDRESS, SEX, SALARY, SUPERSSN, DNA) TA DEPARTMENT(DNAME, DNUMBER. MESSINS, MGRSTARTDATE) DEPT_LOCATIONS(DNUMBER. DLOCATION PROJECT(PNAME, PNUMBER. PLOCATION, DNLIM) WORKS_ONCESSN.PNG, HOURS) DEPENDENTESSN, DEPENDENT-NAME, SEX, BDATE, RELATIONSHIP) Write SQL statements for the following queries: a) List the names of those employees who work in the "Production" department (6 marks). b) Find the maximum salary, minimum salary, and the average salary among employees who work for the "Production department (6 marks). Count the...

  • Given the following relational database schema (primary keys are bold and underlined). Answer questions 2.1 to 2.4 Orde...

    Given the following relational database schema (primary keys are bold and underlined). Answer questions 2.1 to 2.4 Orders(orderld, customerld, dateOrdered, dateRequired, status) Customer(customerld, customerLastName, customerStreet, customerCity, customerState, customer Lip OrderDetails(orderld.productld, quantity, lineNumber, amount) Products(productld, name, description, quantity, unitPrice) Account(accountNumber, customerld, dateOpened, creditCard, mailingStreet, mailingCity, mailingState, mailingZip) 2.1 (2 Points) List all possible foreign keys. For each foreign key list both the referencing and referenced relations. 2.2 (2 Points) Devise a reasonable database instance by filling the tables with data of...

  • 1. Given the following database schema owner(owner_name, age) owns(owner_name, num_cats) Write relational algebra for the following:...

    1. Given the following database schema owner(owner_name, age) owns(owner_name, num_cats) Write relational algebra for the following: Find the name of all owners above the age of 50 Find the name of all owners who own fewer than 5 cats Find the name of all owners who are below the age of 24 and own more than 4 cats 2. Given the following database schema person(name, age, account_id) account(account_id, balance) Write a relational algebra for the following Find the name of...

  • 3. (20 POINTS) Consider the LIBRARY relational database schema below to write down the relational algebra...

    3. (20 POINTS) Consider the LIBRARY relational database schema below to write down the relational algebra expressions for the following two queries. No SQL statements are required. BOOK Bookid Title Publisher name BOOK AUTHORS Book id Author name PUBLISHER Name Address Phone BOOK COPIES Book d Branch Id No o copies BOOK LOANS Book Branch Id Card no Date out Due date LIBRARY BRANCH Branch Branch name Address BORROWER Card Name Address Phone 3.A.) (10 POINTS) Let the number of...

  • Translate the following query into extended Relational Algebra Find every person who is skilled at the...

    Translate the following query into extended Relational Algebra Find every person who is skilled at the manufacture of more products manufactured by company 111-22-3333 than the average number of the company’s products at which employees of the company are skilled company(co_name, govt id, ceo_ssn, hq_loc) division(co id, div name, subdiv_of, dir_ssn, div_hq) site(co id, divname, loc) product(prod id, manuf co, manuf_div, loc, prod_descr) person(ssn, name, address) works_for(ssn, co id, div_name, salary, emp_id, sup_ssn) skill(ssn, prod id, manuf co company(co_name, govt...

  • using the University database we have provided you with the creation script using the relational schema...

    using the University database we have provided you with the creation script using the relational schema of a University as shown below. You should run this script in MySQL Workbench and use this database to extract the necessary information. The script is based on the following relational schema: Subject (subjectCode, departmentName) TeachingStaff (employeeNumber, firstName, surname, departmentName) Instructs (employeeNumber, subjectCode, studentID, position) Student (studentID, studentSurname, studentInitials, gender) TeachingCredentials (employeeNumber, degreecode, uni, awardYear) Enrolment (studentId, degreeCode, year, uni, timeMode, placeMode, completed) Grades...

  • TM-315 DATABASE SYSTEMS Please help me to draw an ERD and the Relational Schema and please...

    TM-315 DATABASE SYSTEMS Please help me to draw an ERD and the Relational Schema and please mark the Primary and Foreign Key ..... Deliverable: Word document with grade sheet followed by Part 1 ERD and the Part 2 relational schema. Part 1: Draw the ERD for the following situation. 8 pts Be sure to: Convert all many-to-many relationships to associative entities. Make sure each regular entity has an appropriate identifier. Make sure attribute names are unique within the ERD Wally...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT