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
WEEKDAY(date)
Возвращает индекс дня недели для аргумента date (0 =понедельник, 1 = вторник, ... 6 = воскресенье):
mysql> SELECT WEEKDAY('1997-10-04 22:23:00');
-> 5
DELETE from POSTS where time_to_delete<NOW()