Giter VIP home page Giter VIP logo

hw2-s19's Introduction

Homework 2

  • Assigned: Feb 21
  • Due: Mar 5 at 10:00AM
  • Worth 3.75% of your grade

Solution

Solution released!

Submission

Format

Use this template

Submit your pdf on GradeScope

1. Relational Algebra

(2 points each, 6 points total)

Consider the simplified Employee Stock Ownership Database below (primary keys are in bold):

  • Person(ssn, companyid, salary, managerid)

This is an employee table. companyid is a foreign key which points to Company. We assume one employee can only work at one company. managerid is a foreign key which points to another Person record .

  • Company(companyid, companyname, location)

  • Holding(ssn, companyid, sharenum)

Holding table describes an employee(ssn) owns sharenum stocks of companyid.

Construct relational algebra for the following queries:

  • Q1: Find the ssn of the persons who work at Google(companyid = 601) and hold more than 500 sharenum of stock from Facebook(companyid = 700).

  • Q2: Find the ssn of the persons who own all the different kinds of stocks his/her manager owns. (Note: Each companyid represents a different kind of stock, we do not care about the sharenum of stocks).

  • Q3: Find the ssn of the persons who own at least three different kinds of stocks.

2. More Relational Algebra

(2 point each, 10 points total)

T1

A B C
1 x a
2 y c
2 y b
2 z c

T2

B C D
1 x c
2 y c
3 x a

Write the result table for the relational algebra expressions in a similar with T1 and T2:

Note: Here, we assume the attributes whose values are all numbers are the same type: integers and all the letters are the same type: char. If the result table is empty, write the schema of the table.

  1. πA,B(T1)

  2. T1 × πA(T1)

  3. T1 ⨝T1.B=T2.C T2

  4. T1 − (T1 ∩ T2)

  5. T1 ⨝T1.A<T2.BB<=2(T2))

3. SQL

(2 points each, 6 points total)

Here are three relationship, (primary keys are in bold):

  • Store(storeid, s_name, employee_number, city)

  • Goods(g_id, g_name, price)

  • Supply(storeid, g_id)

Requirements:

First, describe the meaning of following relational algebra expressions in one or two sentences. Second, translate the following relational algebra expressions in SQL. Make sure your SQL can be executed.

  1. πstoreid, s_nameemployee_number<=100 or city = "New York"(Store))

  2. πs_name(((σg_name = "pencil"Goods) ⨝ Supply) ⨝ Store)

  3. πs_name, city((Supply/πg_idstoreid='0808'(Supply)))⨝ Store)

hw2-s19's People

Contributors

ireneruru avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.