Loading
Lesson 31
Courses / HackerRank SQL Problem Solving Solution Challenges
Revising Aggregations - The Sum Function | SQL Aggregation | HackerRank Solution

Video Transcript

Hey everybody, welcome to another lesson. I'll be doing revising aggregations, the sum function from the aggregation subsection of SQL and hacker rank. So we're given the stable city has the column ID named country code district and population. We're asked to pair with the total population of all cities where a district is California. So basically we have a bunch of rows and those rows have population column that has a number. So we have to take all those numbers and add them up except we can only take the rows that have the district value California. So this solution will work for DB2 and my SQL. Let's go. So we're gonna first do I just select star from city and then we're gonna add on to this. So we want to query the population where district is. Let's do where district is California. So we're gonna filter, we're gonna add a where and district is the column and that value has to be equal to California like this. Now what column do we query here? Well, we query the total population. So we have to sum all the values for the population column. So we got to say sum of and then you put population. That's the column name here. So this is gonna take the value of each population column, add them up and bring you the sum and we have a filter here for only the rows that are from California. And there you go. You're gonna collect submit code and that's revising aggregations the sum function.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: