Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SQL Programming I am having trouble writing the correct code, any help would be

ID: 3585368 • Letter: S

Question

SQL Programming

I am having trouble writing the correct code, any help would be great.

Using subqueries

1.    This query uses only the countryLanguage table. Create a query that lists the countrycode, number of distinct languages spoken in that country, along with the % of languages spoken to total languages.


My code so far



SELECT CountryCode, (Count(Language) * 100 / (SELECT COUNT(*) FROM country))AS Language%
WHERE country.countrycode=language.countrycode;

-16 country 15202600-1 . city ID int(11) Name: char(35) CountryCode: char(3) 6 countrylanguage a CountryCode: char(3) a CountryCode char(3) Name:char(52) Continent:char(15) Language:char(30) somci al : enum(TF) Region:char(26) n SurfaceArea:oat(10,2) # Indeprear: smallint(6) n Population: int(11) # Life Expectancy : noat(31) n GNP float 10,2) #GNPOld float(10,2) District: char(20) # Percentage : float(4,1) Population : int11) LocalName: char(45) GovernmentForm: char(45) HeadofState: char(60) # capital : int(11) Code2 : char(2)

Explanation / Answer

Query for the question:

SELECT CountryCode, COUNT(DISTINCT Language) as no_of_langauges, (no_of_langauges * 100 / sum(no_of_langauges)) AS Language%
FROM countryLanguage
GROUP BY CountryCode;

percentage for each language is given in the same table, so i think summing the percentage column for each country is the right answer.

SELECT CountryCode, COUNT(DISTINCT Language) as no_of_langauges, sum(percentage) AS tot_percentage
FROM countryLanguage
GROUP BY CountryCode;