알고리즘/codefightsDB

17>countriesInfo

Diademata 2019. 3. 13. 16:02
반응형

Your friend wants to become a professional tour guide and travel all around the world. In pursuit of this dream, she enrolled in tour guide school. The professors in this school turned out to be very demanding, and one of them gave your friend a difficult assignment that she has to finish over the weekend.


Here's the task: Given a list of countries, your friend should calculate the average population and total population of all the countries in the list. To help her, you have decided to write a function that will calculate the required values for any number of countries. The countries table in which the countries are stored has the following structure:


name: the name of the country;

continent: the continent on which the country is situated;

population: the population of the country.

Your task is to return a new table that contains the number of countries in the given list, along with their average and total population, in columns titled number, average and total.


code>>


/*Please add ; after each select statement*/

CREATE PROCEDURE countriesInfo()

BEGIN

select count(name) as number,

    SUM(population) / count(name) as average,

    SUM(population) as total

    from countries;


END

반응형

'알고리즘 > codefightsDB' 카테고리의 다른 글

19>usersByContinent  (0) 2019.03.25
18>itemCounts  (0) 2019.03.13
16>newsSubscribers  (0) 2019.03.13
15>expressionsVerification  (0) 2019.03.13
14>testCheck  (0) 2019.03.13