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 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 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...
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.
Given the below relational algebra expressions, use domain and tuple relational calculus to specify them: a....
Given the below relational algebra expressions, use domain and tuple relational calculus to specify them: a. σx=z ( R(a,b,c) ) b. πx,y ( R(x,y,z) ) c. R(x, y) / S(x) d. R(a,b,c) ∪  S(a,b,c) e. R(a,b,c) – S(a,b,c) f. R(d,e,f) ∩ S(d,e,f) g. R(x,y,z) × S(f,g,t)
Write a template class Number with the following features Overload following operators for the template class...
Write a template class Number with the following features Overload following operators for the template class + - < > Overload << and >> operators for the ostream and istream against this class. Write a main function to demonstrate the functionality of each operator.
Write a template class Number with the following features Overload following operators for the template class...
Write a template class Number with the following features Overload following operators for the template class + - < > Overload << and >> operators for the ostream and istream against this class. Write a main function to demonstrate the functionality of each operator.
--Know how to do tuple comparison in queries. --Know how to use operators with nulls, and...
--Know how to do tuple comparison in queries. --Know how to use operators with nulls, and know the is null and is not null operators. --Be able to use the aggregate functions avg, count, min, max, and sum and know how to use them with group by and having. --Know how aggregation works with null values. Study guide can you please provide examples
) Write queries for the following. Include screenshots of the queries and the outputs. Create a...
) Write queries for the following. Include screenshots of the queries and the outputs. Create a procedure named DisplayInfo which takes customer name as a parameter and displays information of that customer. (database – sql_store)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT