a silly solution with subqueries only, no parameters


  • 0
    D
    # Write your MySQL query statement below
    
    
    
    #select  avg(number) median from
    
    #(select floor((sum(frequency)+1)/2) lower, ceil((sum(frequency)+1)/2) upper from numbers) n3,
    
    #(select number, (select sum(n2.frequency) from numbers n2 where n2.number<=n1.number ) running_total from numbers n1 group by number ) n4
    
    #where upper-1>=running_total and lower+1<=running_total
    
    
    select (maximum + minimum)/2 median from 
    
    (select  min(number) maximum from
    
    (select floor((sum(frequency)+1)/2) lower, ceil((sum(frequency)+1)/2) upper from numbers) n3,
    
    (select number, (select sum(n2.frequency) from numbers n2 where n2.number<=n1.number ) running_total from numbers n1 group by number ) n4
    
    where upper<=running_total) n5, 
    
    (select  min(number) minimum from
    
    (select floor((sum(frequency)+1)/2) lower, ceil((sum(frequency)+1)/2) upper from numbers) n3,
    
    (select number, (select sum(n2.frequency) from numbers n2 where n2.number<=n1.number ) running_total from numbers n1 group by number ) n4
    
    where lower<=running_total) n6
    
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.