Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following tables with the structure: 1. athletes(id integer,sex text,dob text, height float, weight integer, nationality text ) (File in: https://ufile.io/escnl) 2. countries(country text,code

Given the following tables with the structure:

1. athletes(id integer,sex text,dob text, height float, weight integer, nationality text ) (File in: https://ufile.io/escnl)

2. countries(country text,code text, population integer, gdp float) (File in: https://ufile.io/hjot8)

3. games(id integer,name text, nationality text, sport text,gold integer, silver integer, bronze integer) (File in: https://ufile.io/oi758)

Use SQLite3:

1. Notice that some of the cells in the population column of countries are empty strings. Use the following command to explicitly set these empty cells to NULL by updating the table as follows:

UPDATE countries SET population = NULL where population='';

With the empty cells filled with null values, you can use the IS NOT NULL keyword to exclude such rows in any query.

Once you have updated the countries table to fill the empty cells with null values, list the top 5 most populated countries along with the sum of all medals (i.e., gold, silver and bronze combined) won by the country. Your result should be ordered by country population, from highest to lowest.

For example: if United States has won 10 medals in total and United Kingdom has won 12, but USA is more populated than UK , then your result should order them as follows: United States, 10 United Kingdom, 12

Format of each line in the output (5 lines total): full_country_name, sum_of_medals

2. find the top 5 countries with the highest number of female athletes who have won at least one gold medal. List the names of these countries (full names and not the country code) along with their respective female athlete counts as output. Your output should be ordered by the count from highest to lowest. Format of each line in the output (5 lines total): full_country_name, count_of_gold_winning_female_athletes

3. The BMI of a person is calculated as the ratio of their weight (in kilograms) to their squared height (in meters). A person is considered fit if his or her BMI is between 18.5 (inclusively) and 24.9 (inclusively).

Find the athletes who are fit (according to the above definition) and list their names along with their BMI values. Sort the list first alphabetically by their names and then by their BMI values from lowest to highest, and limit the result to 10 rows. Note: The athletes table lists the height in meters and weight in kilograms.

Format of each line in the output: athlete_name, bmi_value

Hint: Consider using BETWEEN .

4. Calculate the percentage of gold medals and silver medals won by each country in INTEGER FORMATonly (if you use float in your intermediate calculations, then round down the final value using CAST(value as int) ). Order the countries first by their gold medal percentage (highest to lowest) and then by their silver medal percentage (highest to lowest). List the full names of the countries along with their gold and silver medal percentages. Limit the result to the top 20 countries.

Format of each line in the output (20 lines total): full_country_name, gold_medal_percentage, silver_medal_percentage

Hint: Consider using SELECT statements to find the denominator in the percentage calculation.

Note: Percentage of gold medals won by a country = Number of gold medals won by that country / Total number of gold medals in the olympics.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions