Hacker Rank SQL

Revising Aggregations – The Sum Function Solution

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


Also Visit: Revising Aggregations – The Count Function Solution


 

Problem

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

Input Format

The CITY table is described as follows:

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

 

Solution – Revising Aggregations – The Sum Function

MySQL Code
select sum(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. The SUM function

The SUM function

The SUM function adds values. You can add individual values, cell references or ranges or a mix of all three. For example: =SUM(A2:A10) Adds the values in cells A2:10. =SUM(A2:A10, C2:C10) Adds the values in cells A2:10, as well as cells C2:C10.

 

 

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.