Question

In: Computer Science

Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class...

Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming).

The following database schema is given:

ATHLETE(name,age,height,weight,country) RACE(id,location,date,time-start,distance) COMPETES(aname,rid,time,position)

where ATHLETE has information about runners (their name, age, height, weight, and nationality); RACE has information about races (id, location, date when it’s held, time it starts, and distance ran); and COMPETES keeps track of which runners run on with race, the time it took them to complete the race, and their position on it (winner = ’1’, second = ’2’, third = ’3’, and so on).

(a) List the names of athletes under 30 years old from Norway that have ran a marathon (distance=26.2).

(b) List the names of athletes who have finished a race in 1st position and another race in second position.

(c) List the names of athletes who have never won a race (win=1st position).

(d) (*) List the races (id) where all the athletes were under 30 years old.

Solutions

Expert Solution

The relational algebra operators used are:

  • Projection: The operator shows the list of the attributes required in the result. All the other attributes are eliminated from the result.
  • Selection: The operator selects the tuples that specify the given conditions.
  • Join (AND operator): The operator joins the conditions to give the result to be projected.

(a) Relational Algebra:

Explanation: The expression projects the name from the athlete table where the following conditions are true:

- The age is less than 30

- The country is 'Norway'

- The distance is equal to 26.2. The distance is taken from the race table

(b) Relational Algebra:

Explanation: The expression projects the name of athletes who have finished the race at 1st and 2nd position.

(c) Relational Algebra:

Explanation: The expression projects the name of the athletes who have never won a race. The data is taken from the competes table.

(d) Relational Algebra:

Explanation: The expression projects the race id from the race table, for the athletes who are under 30. The age data is taken from the athlete table.


Related Solutions

Write the following questions as queries in Relational Algebra. Use only the operators discussed in class...
Write the following questions as queries in Relational Algebra. Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming —in particular, no outer joins or aggregations). Type your answers. If you can’t find Greek letters in your word processor, you can simply write out the operator, all uppercase (i.e. ’SELECT’). Please use renaming consistently, as indicated in the handout. Before starting, make sure you understand the schema of the database. If you...
Write the following questions as queries in SQL. Use only the operators discussed in class (no...
Write the following questions as queries in SQL. Use only the operators discussed in class (no outer joins) Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid is a foreign...
Write the following questions as queries in SQL. Use only the operators discussed in class (no...
Write the following questions as queries in SQL. Use only the operators discussed in class (no outer joins) Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid is a foreign...
Given the following relational schema, write queries in SQL to answer the English questions. There is...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Given the following relational schema, write queries in SQL to answer the English questions. There is...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Write the following queries using relational algebra. SHOW ALL STEPS CREATE TABLE MovieStar (msid char(3), msname...
Write the following queries using relational algebra. SHOW ALL STEPS CREATE TABLE MovieStar (msid char(3), msname char(10), title char(4), PRIMARY KEY(msid)); msid – movie star ID, msname – star’s name, title – denotes gender (“Mr.’, “Mrs.”, “Ms.”) CREATE TABLE Stars_in (msid char(3), mid char(3), contract number(9,2), duration number(2), PRIMARY KEY (msid, mid), FOREIGN KEY(msid) REFERENCES MovieStar, FOREIGN KEY(mid) REFERENCES Movie); contract – the star’s salary for the movie, duration – contract duration in months. CREATE TABLE Movie (mid char(3), mname...
This is t a relational database please write SQL queries to solve the listed questions. The...
This is t a relational database please write SQL queries to solve the listed questions. The database is a variation of the “Movie Database” . There are several differences in it, so look it over carefully before writing your SQL queries Notes: TheaterNum, MovieNum, and ActorNum are numeric primary key fields in their respective tables. Movie and actor names are not assumed to be unique unless specified otherwise in a question. In the THEATER table, Capacity is the number of...
Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference...
Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming). Type your answers. The following database schema is given: ATHLETE(name,age,height,weight,country) RACE(id,location,date,time-start,distance) COMPETES(aname,rid,time,position) where ATHLETE has information about runners (their name, age, height, weight, and nationality); RACE has information about races (id, location, date when it’s held, time it starts, and distance ran); and COMPETES keeps track of which runners run on with race, the time it took them to complete the race,...
Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference...
Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming). Type your answers. Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid...
Write a C++ program that uses all the relational operators.
Write a C++ program that uses all the relational operators.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT