create Table numbers (number int,frequency int);
insert into numbers values (1,2);
insert into numbers values (4,1);
insert into numbers values (6,2);
insert into numbers values (9,1);
with cte2 as(
select n.*,
sum(frequency) over (order by number) as acc_sum,
sum(n.frequency) over() as sum_freq from numbers n
)
select avg(c2.number) from cte2 c2
where c2.acc_sum between sum_freq/2 and (sum_freq/2)+c2.frequency;
No comments:
Post a Comment