Relational Algebra Queries for Athlete Events

Answered using GPT-4o mini by AI Answer Generator

Question:

ATHLETE (AthleteNo, AthleteName, CountryName) COUNTRY (CountryName, NumberOfCompetitors) EVENT (EventName, ScheduledStart, VenueName) VENUE (VenueName, Location, Capacity) FINAL (AthleteNo, EventName, Place, Medal)

Provide Relational Algebra (NOT SQL) queries, with description as necessary to find the following information. Each question is worth 2 marks. NOTE: • You can use the symbols , , etc or the words ‘PROJECT’, ‘RESTRICT’ etc as you prefer.
• You do not need to try to make efficient queries – just correct ones. • Where you use a join, always show the join condition. • Provide a description to explain how the query will run.

  1. List the name and country of all athletes.  Name,Country(ATHLETE)

  2. List the event name and scheduled start time for all events held in the Velodrome.

  3. List the names of athletes who competed in an event in Rio de Janeiro, Sao Paolo, or both.

  4. List the names of all Brazilian athletes who won a gold medal.

  5. List full details of the events that were held in venues with a capacity of over 50,000.

  6. List the name and location of all venues, and the events that were scheduled to be held in them (if any).

  7. List the names of Australian athletes who won a gold medal in an event held in the Aquatics Stadium.

  8. List the name of any athlete who was placed 1 in both the Men’s 100m and 200m.

  9. List the names of the athletes who did NOT win a medal in the Women's 1500m Freestyle.

  10. List the name of any athletes who won a gold medal in all the events he or she competed in.

Answer:

Here are the relational algebra queries for the specified tasks, along with descriptions of how each query operates:

1. List the name and country of all athletes.

Query: [ \Pi_{AthleteName, CountryName}(ATHLETE) ] Description: This query projects the AthleteName and CountryName attributes from the ATHLETE relation, resulting in a list of all athletes along with their respective countries.


2. List the event name and scheduled start time for all events held in the Velodrome.

Query: [ \Pi_{EventName, ScheduledStart}(\sigma_{VenueName = 'Velodrome'}(EVENT)) ] Description: This query restricts the EVENT relation to only those events where the VenueName is 'Velodrome' and then projects the EventName and ScheduledStart attributes.


3. List the names of athletes who competed in an event in Rio de Janeiro, Sao Paolo, or both.

Query: [ \Pi_{AthleteName}((\sigma_{Location = 'Rio de Janeiro'}(VENUE) \bowtie EVENT) \bowtie FINAL) \cup (\sigma_{Location = 'Sao Paolo'}(VENUE) \bowtie EVENT) \bowtie FINAL) ] Description: This query first finds venues in Rio de Janeiro and Sao Paolo, joins them with the EVENT relation to get the events held at those venues, and then joins with the FINAL relation to get the athletes who competed in those events. Finally, it projects the AthleteName from the results.


4. List the names of all Brazilian athletes who won a gold medal.

Query: [ \Pi_{AthleteName}((\sigma_{Medal = 'Gold'}(FINAL) \bowtie ATHLETE) \sigma_{CountryName = 'Brazil'}) ] Description: This query restricts the FINAL relation to only those records where the Medal is 'Gold', then joins with the ATHLETE relation to find the corresponding athletes, and finally restricts to those athletes from Brazil before projecting their names.


5. List full details of the events that were held in venues with a capacity of over 50,000.

Query: [ \Pi_{*}((\sigma_{Capacity > 50000}(VENUE) \bowtie EVENT)) ] Description: This query restricts the VENUE relation to those venues with a Capacity greater than 50,000, then joins with the EVENT relation to get the full details of the events held in those venues, projecting all attributes.


6. List the name and location of all venues, and the events that were scheduled to be held in them (if any).

Query: [ \Pi_{VenueName, Location, EventName}((VENUE \bowtie EVENT) \cup (VENUE \times \Pi_{EventName}(EVENT)) ] Description: This query performs a natural join between VENUE and EVENT to get venues with scheduled events, and also includes venues with no events scheduled by using a Cartesian product with an empty projection of EventName. It then projects the VenueName, Location, and EventName.


7. List the names of Australian athletes who won a gold medal in an event held in the Aquatics Stadium.

Query: [ \Pi_{AthleteName}((\sigma_{VenueName = 'Aquatics Stadium'}(EVENT) \bowtie FINAL) \bowtie (\sigma_{CountryName = 'Australia'}(ATHLETE)) \sigma_{Medal = 'Gold'}) ] Description: This query restricts the EVENT relation to those held in the 'Aquatics Stadium', joins with the FINAL relation to find athletes who participated, and then joins with the ATHLETE relation to filter for Australian athletes who won a gold medal, projecting their names.


8. List the name of any athlete who was placed 1 in both the Men’s 100m and 200m.

Query: [ \Pi_{AthleteName}((\sigma_{EventName = 'Men’s 100m'}(FINAL) \bowtie \sigma_{Place = 1}(FINAL)) \cap (\sigma_{EventName = 'Men’s 200m'}(FINAL) \bowtie \sigma_{Place = 1}(FINAL))) ] Description: This query finds athletes who placed 1 in both the Men’s 100m and 200m events by intersecting the results of two selections from the FINAL relation, each filtered for the respective event and place, and then projecting the AthleteName.


9. List the names of the athletes who did NOT win a medal in the Women's 1500m Freestyle.

Query: [ \Pi_{AthleteName}(ATHLETE) - \Pi_{AthleteName}(\sigma_{EventName = 'Women’s 1500m Freestyle'}(FINAL)) ] Description: This query first projects all athlete names from the ATHLETE relation, then subtracts the names of athletes who participated in the Women's 1500m Freestyle event from the FINAL relation, resulting in athletes who did not win a medal in that event.


10. List the name of any athletes who won a gold medal in all the events he or she competed in.

Query: [ \Pi_{AthleteName}(\sigma_{Medal = 'Gold'}(FINAL)) \div \Pi_{AthleteNo, EventName}(FINAL) ] Description: This query first selects athletes who won a gold medal from the FINAL relation, then divides this set by the set of all athletes and events they competed in, resulting in athletes who won gold in every event they participated in. The division operator ensures that only those athletes who meet the criteria are included in the final result.