select
case t.price > 10 then 2 else 1 end col
from t
group by case t.price > 10 then 2 else 1 end ;
select
avg(price), col
from (
select
price,
case t.price > 10 then 2 else 1 end col
from t)
group by col ;
select *
from clients c
where exists (
select null
from (select abs(principal - lag(principal) over(partition by client_id order by report_date)) diff
from principals p
where p.client_id = c.client_id
)
where diff < c.payment_need
and diff is not null)