본문 바로가기
언어

percent_rank, ntile

by 땅호720 2024. 7. 8.

 

with ecoli_ds as (select *,
percent_rank() over(order by size_of_colony desc) 'pr'
from ecoli_data)

select id,
case
when pr <= 0.25 then 'CRITICAL'
when pr <= 0.5 then 'HIGH'
when pr <= 0.75 then 'MEDIUM'
else 'LOW'
end as 'COLONY_NAME'
from ecoli_ds
order by id

 

with ecoli_ds as (select *,
percent_rank() over(order by size_of_colony desc) 'pr'
from ecoli_data)

select id,
case
when pr between 0 and 0.25 then 'CRITICAL'
when pr between 0.25 and 0.5 then 'HIGH'
when pr between 0.5 and 0.75 then 'MEDIUM'
else 'LOW'
end as 'COLONY_NAME'
from ecoli_ds
order by id

 

with ecoli_ds as (select *,
ntile(4) over(order by size_of_colony desc) 'pr'
from ecoli_data)

select id,
case
when pr=1 then 'CRITICAL'
when pr=2 then 'HIGH'
when pr=3 then 'MEDIUM'
else 'LOW'
end as 'COLONY_NAME'
from ecoli_ds
order by id

'언어' 카테고리의 다른 글

데이터 조합 형식  (0) 2024.07.10
union all  (0) 2024.07.08
비트연산  (0) 2024.07.02
recursive & repeat  (0) 2024.06.25
interviews  (0) 2024.06.20