Lesson 15
Weather Observation Station 15 | SQL Aggregation | HackerRank Solution
Video Transcript
Hey everybody, welcome to another lesson. I will do weather observation 15 for the subsection
aggregation of the SQL section from Hackadrank. In this question we're given the stable station
that has five columns ID, city, state, lat, underscore, n, and long underscore, w. And
we're asked to query the western longitude that's the long underscore, w value for the
largest nor the latitude, lat, underscore, n. That's less than 137.2 and is 345. And make
sure to round not truncate, keep that in mind, your answer to four decimal places. So the
thing with this question is we're asked to find a row that has the largest lat n that's
less than 137.2 and 345. And from that row, we have to take the value long underscore,
w. And to do that question, I'm going to do an order by and I'll order by the and take
the very first row as the greatest lat n score n. Let me show you what I mean. First,
I will choose my SQL and I always like to visualize the data. So I'll select star from
station to see what it looks like. Okay, so we have all these values for lat underscore
n here, we have to find out what's the greatest, the row of the greatest and from that row,
we take this long underscore w value. So what I'm going to do here, let's do where let's
make sure the lat underscore n is within the range that's required by the question. So
it has to be less than 137.2 and 345. That's fine. And then from that, let's do the following.
So I want to order by the lat underscore n value, but descending meaning the very first
row is going to have the greatest value. So I'm going to say order by lat underscore n
and the ESC to say descending. Now this is going to give us multiple roles, right? But
I only want the first row that has the greatest value for lat underscore n within this range.
So I'm going to say limit one to only take the very first row. And then from that, we
have to select what we have to take the value from long underscore w. So we're going to
say long underscore w here. And this is the answer, but because it's not rounded, you
can see there's like eight digits after to the right of the decimal point. So we'll have
to make sure to round your answer to four decimal places, meaning this one would actually
become 0.2465. So to do that, you go here where we have long w and you say round parentheses,
and then comma has to be four decimal places, close parentheses, this will take that value
and just round to four digits to the right of the decimal place. Okay, so now we have
0.2465. Let me submit. And that's whether observation station 15.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: