Hacker Rank SQL

Revising Aggregations – Averages Solution

Hello Friends in this article i am gone to share Hacker Rank SQL Solutions with you | Revising Aggregations – Averages Solution


Also Visit: Revising Aggregations – The Sum Function Solution


 

Problem

Query the average population of all cities in CITY where District is California.

Input Format

The CITY is described as follows:

Field Type
ID NUMBER
NAME VARCHAR2(17)
COUNTRYCODE VARCHAR2(3)
DISTRICT VARCHAR2(20)
POPULATION NUMBER

 

Solution – Revising Aggregations – Averages

MySQL Code
select avg(population) 
from city where district='California';

 


What do you mean by aggregation in SQL?

SQL aggregation is the task of collecting a set of values to return a single value. It is done with the help of aggregate functions, such as SUM, COUNT, and AVG. For example, in a database of products, you might want to calculate the average price of the whole inventory.

Averages Aggregations

A single-value metrics aggregation that computes the average of numeric values that are extracted from the aggregated documents. These values can be extracted either from specific numeric or histogram fields in the documents.

Note: AVG is an aggregation function used to calculate the average of the values of all the records in the specified column name passed to the function

 

Disclaimer: The above Problems are generated by Hacker Rank but the Solutions are Provided by NYANDER.COM. All Hacker Rank SQL Solutions Shared only for Educational and Learning Purpose.