select avg(age)
from (select t.*,
row_number() over (order by age) as seqnum,
count(*) over () as cnt
from t
) t
where seqnum * 2 in (cnt, cnt + 1, cnt + 2);
select name, age
from (
select
name,
age,
row_number() over (order by your_order_by_list) r,
count(*) over () c
from
your_table) t
where r = cast((c + 1) / 2 as int);
2条答案
按热度按时间yx2lnoni1#
中间的元素是柱的中间部分。有几种方法可以做到这一点。可靠的方法是:
这适用于偶数行和奇数行。它确实假设“年龄”是数字(所以
avg()
将工作)。ffdz8vbo2#
您可以使用分析函数row\u number()和count()找到中间一行,如下所示: