Hackerrank SQL - Aggregation

  01 Dec 2019
  tsql

Following problems are discussed here. To solve the same, please visit hackerrank website.


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)