Hackerrank SQL - Aggregation


Following problems are discussed here. To solve the same, please visit hackerrank website{:target="_blank"}.


Weather Observation Station 17

select cast(Long_w as decimal(9,4)) from station where lat_n = (select min(Lat_n)  from station where Lat_n  > 38.7780) 

Weather Observation Station 18

select  cast((max(long_w) - min(long_W) + max(lat_n) - min(lat_n)) as decimal(9,4)) from station

Weather Observation Station 19

select  
cast
(
    sqrt
    (
        (square
            (max(long_w) - min(long_W)) 
        + 
        (square
            (max(lat_n) - min(lat_n)))
        )
    )
    as decimal(9,4)
) from station

Weather Observation Station 20

with rowtabel  as (select lat_n, (row_number() over (order by lat_n)) as rn from station)
select cast(lat_n as decimal(9,4)) from rowtabel where  rn in (select (count(lat_n)/2)+1 from station) 

Related Posts

Hackerrank SQL - Advanced Select

December 1, 2019

Read More
T-SQL - Working with subqueries and APPLY

January 1, 2019

Read More
T-SQL - Introduction (Part 1)

January 1, 2019

Read More