# HackerRank: [SQL Aggregation] (9/17) Weather Observation Station-2 | round, sum function in SQL

I started studying SQL from a very famous site - HackerRank. Here I will try to provide multiple approaches & solutions to the same problem. It will help you learn and understand SQL in a better way.

Please make use of my blog posts for learning purpose only and feel free to ask your questions in the comment box below in case of any doubt.

Recommended SQL Courses:

SQL Problem Statement:

Query the following two values from the STATION table:

1. The sum of all values in LAT_N rounded to a scale of 2 decimal places.
2. The sum of all values in LONG_W rounded to a scale of 2 decimal places.

Input Format:

The STATION table is described as follows:

 Table: STATION
where LAT_N is the northern latitude and LONG_W is the western longitude.

Sample data in Table (STATION):
`ID CITY STATE LAT_N LONG_W794 Kissee Mills MO 140 73824 Loma Mar CA 49 131603 Sandy Hook CT 72 148478 Tipton IN 34 98619 Arlington CO 75 93711 Turner AR 50 101839 Slidell LA 85 152...754 South Haven MI 145 53144 Eskridge KS 1`

Output Format:

Your results must be in the form:
`lat lon`

where lat is the sum of all values in LAT_N and lon is the sum of all values in LONG_W. Both results must be rounded to a scale of 2 decimal places.

### Solution: Using ROUND & SUM Function (MySQL Query):

`SELECT  ROUND(SUM(LAT_N), 2) AS lat,  ROUND(SUM(LONG_W), 2) AS lonFROM STATION;`

NOTE:
1. ROUND Function is used to round the decimal numbers up to mentioned length after the decimal point. Here, 2 is passed because we want output scale up to 2 decimal points.
Eg.
ROUND(2.7685, 2) will return 2.77
ROUND(2.3327, 0) will return 2.33
2. SUM is an aggregation function used to calculate the sum or total of the values of all the records in the column name passed to the function.

### Expected Output:

`42850.04 47381.48`

--------------------------------------------------------------------------------