[--order--]
1
2
3
4
5
6
with inp as (
select 1 id from dual union all
select 2 from dual union all
select 3 from dual union all
select 4 from dual union all
select 5 from dual union all
select 6 from dual)
SELECT
id
FROM
inp
ORDER BY
abs( (
SELECT
AVG(id)
FROM
inp
) - id),
id;
select *, (abs(avg_column-column)) as sorting_column from orders i
left join (select avg(column) as avg_column from orders) o on...
order by sorting_column