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.
Click Here for the previous blog-post in the series.
Recommended SQL Courses:
SQL Problem Statement:
Query the following two values from the STATION table:
- The sum of all values in LAT_N rounded to a scale of 2 decimal places.
- 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 |
Sample data in Table (STATION):
Output Format:
Your results must be in the form:
Solution: Using ROUND & SUM Function (MySQL Query):
NOTE:
- 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 - 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:
--------------------------------------------------------------------------------
Click here to see solutions for all Machine Learning Coursera Assignments.
&
Click here to see more codes for Raspberry Pi 3 and similar Family.
&
Click here to see more codes for NodeMCU ESP8266 and similar Family.
&
Click here to see more codes for Arduino Mega (ATMega 2560) and similar Family.
Feel free to ask doubts in the comment section. I will try my best to answer it.
If you find this helpful by any mean like, comment and share the post.
This is the simplest way to encourage me to keep doing such work.
Thanks & Regards,
-Akshay P Daga